This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
BaseDocument doc = (BaseDocument)target.getDocument();
Caret caret = target.getCaret();
int dotPos = caret.getDot();
Formatter formatter = doc.getFormatter();
formatter.indentLock();
DocumentUtilities.setTypingModification(doc, true);
try{
target.replaceSelection("");
int newDotPos = dotPos; // dot stays where it was
final int dotPos = caret.getDot(); // dot stays where it was
formatter.indentNewLine(doc, dotPos); // newline
caret.setDot(newDotPos);
caret.setDot(dotPos);
} finally {
DocumentUtilities.setTypingModification(doc, false);
doc.atomicUnlock();