Auto indent the next line based on the current level of indent.
markolive@mohc.co.uk
Logged In: NO
Add this to methods to the SyntaxDocument and it will work. Maybe not the best way to do, but it works:
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException { if(str.equals("\n")) { str = this.addWhiteSpace(offset); } else if(str.equals("\t")) { str = " "; }
super.insertString(offset, str, a); }
protected String addWhiteSpace(int offset) throws BadLocationException { Element root = this.getDefaultRootElement(); StringBuffer whiteSpace = new StringBuffer(); int line = root.getElementIndex(offset); int i = root.getElement(line).getStartOffset(); while(true) { String temp = this.getText(i, 1); if(temp.equals(" ") || temp.equals("\t")) { whiteSpace.append(temp); i++; } else { break; } } return "\n"+whiteSpace.toString(); }
Log in to post a comment.
Logged In: NO
Add this to methods to the SyntaxDocument and it will work.
Maybe not the best way to do, but it works:
public void insertString(int offset, String str,
AttributeSet a)
throws BadLocationException {
if(str.equals("\n")) {
str = this.addWhiteSpace(offset);
} else if(str.equals("\t")) {
str = " ";
}
super.insertString(offset, str, a);
}
protected String addWhiteSpace(int offset)
throws BadLocationException {
Element root = this.getDefaultRootElement();
StringBuffer whiteSpace = new StringBuffer();
int line = root.getElementIndex(offset);
int i = root.getElement(line).getStartOffset();
while(true) {
String temp = this.getText(i, 1);
if(temp.equals(" ") || temp.equals("\t")) {
whiteSpace.append(temp);
i++;
} else {
break;
}
}
return "\n"+whiteSpace.toString();
}