// make sure line delimiters match to what's supposed to be used in the document.
templateString = templateString.replaceAll("\\r\\n|\\r|\\n", TextUtilities.getDefaultLineDelimiter(document));
document.replace(start, end - start, templateString);
// translate positions
LinkedPositionManager manager = new LinkedPositionManager(document);
TemplatePosition[] variables = templateBuffer.getVariables();
for (int i = 0; i < variables.length; i++)
{
TemplatePosition variable = variables[i];
if (variable.isResolved()) continue;
int[] offsets = variable.getOffsets();
int length = variable.getLength();
for (int j = 0; j < offsets.length; j++)
manager.addPosition(offsets[j] + start, length);
}
LinkedPositionUI editor = new LinkedPositionUI(viewer, manager);
editor.setFinalCaretOffset(getCaretOffset(templateBuffer) + start);
editor.enter();