+ dirty = true;
+ int cursor = lines.get(lineNumber).getCursor();
+ if (cursor > 0) {
+ lines.get(lineNumber).backspace();
+ } else if (lineNumber > 0) {
+ // Join two lines
+ lineNumber--;
+ String firstLine = lines.get(lineNumber).getRawString();
+ if (firstLine.length() > 0) {
+ // Backspacing combining two lines
+ StringBuilder newLine = new StringBuilder(firstLine);
+ newLine.append(lines.get(lineNumber + 1).getRawString());
+ lines.set(lineNumber, new Line(newLine.toString(),
+ defaultColor, highlighter));
+ lines.get(lineNumber).setCursor(firstLine.length());
+ lines.remove(lineNumber + 1);
+ } else {
+ // Backspacing an empty line
+ lines.remove(lineNumber);
+ lines.get(lineNumber).setCursor(0);
+ }
+ }
+ }
+
+ /**
+ * Split the current line into two, like pressing the enter key.
+ */
+ public void enter() {
+ dirty = true;
+ int cursor = lines.get(lineNumber).getCursor();
+ String original = lines.get(lineNumber).getRawString();
+ String firstLine = original.substring(0, cursor);
+ String secondLine = original.substring(cursor);
+ lines.add(lineNumber + 1, new Line(secondLine, defaultColor,
+ highlighter));
+ lines.set(lineNumber, new Line(firstLine, defaultColor, highlighter));
+ lineNumber++;
+ lines.get(lineNumber).home();