case BACKWARD_CHAR: if (to == null) { return EditorAction.LEFT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { return EditorAction.RIGHT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { throw new UnsupportedOperationException("Not yet handled"); return EditorAction.MOVE_NEXT_WORD_AT_BEGINNING.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_UNTIL_NEXT_WORD.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_WORD.repeat(count).then(VI_INSERT); } else { return super.on(keyStroke); return EditorAction.MOVE_PREV_WORD_AT_END.repeat(count).then(VI_MOVE); } else { super.on(keyStroke);
@Override public EditorAction on(KeyStroke keyStroke) { switch (keyStroke.operation) { case BACKWARD_CHAR: return EditorAction.DELETE_PREV_CHAR.then(VI_MOVE); case FORWARD_CHAR: return EditorAction.DELETE_NEXT_CHAR.then(VI_MOVE); case END_OF_LINE: return EditorAction.DELETE_END.then(VI_MOVE); case VI_NEXT_WORD: return EditorAction.DELETE_UNTIL_NEXT_WORD.then(VI_MOVE); case VI_DELETE_TO: return EditorAction.DELETE_LINE.then(VI_MOVE); case INTERRUPT: return EditorAction.INTERRUPT.then(VI_MOVE); default: return VI_MOVE; } }
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { for (int i = 0;i < count;i++) { EditorAction.this.perform(editor, buffer); } } };
@Override public EditorAction on(KeyStroke keyStroke) { switch (keyStroke.operation) { case BACKWARD_CHAR: return EditorAction.DELETE_PREV_CHAR.then(VI_INSERT); case END_OF_LINE: return EMACS.then(EditorAction.DELETE_END).then(VI_INSERT); case VI_NEXT_WORD: return EditorAction.DELETE_NEXT_WORD.then(VI_INSERT); case VI_CHANGE_TO: return EditorAction.DELETE_LINE.then(VI_INSERT); case INTERRUPT: return EditorAction.INTERRUPT.then(VI_MOVE); default: return VI_MOVE; } }
String append(EditorAction action, int[] sequence) { try { return action.execute(this, buffer, sequence, true); } catch (IOException e) { AssertionError ae = new AssertionError("Not yet supported"); ae.initCause(e); throw ae; } }
String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { perform(editor, buffer); if (flush) { buffer.flush(); } return null; }
@Override public EditorAction on(KeyStroke keyStroke) { switch (keyStroke.operation) { case VI_YANK_TO: return EditorAction.COPY.then(VI_MOVE); case END_OF_LINE: return COPY_END_OF_LINE.then(VI_MOVE); case VI_BEGNNING_OF_LINE_OR_ARG_DIGIT: return COPY_BEGINNING_OF_LINE.then(VI_MOVE); case VI_NEXT_WORD: return EditorAction.COPY_NEXT_WORD.then(VI_MOVE); case VI_FIRST_PRINT: return EditorAction.COPY_PREV_WORD.then(VI_MOVE); case INTERRUPT: return EditorAction.INTERRUPT.then(VI_MOVE); default: return super.on(keyStroke); } }
case BACKWARD_CHAR: if (to == null) { return EditorAction.LEFT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { return EditorAction.RIGHT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { throw new UnsupportedOperationException("Not yet handled"); return EditorAction.MOVE_NEXT_WORD_AT_BEGINNING.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_UNTIL_NEXT_WORD.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_WORD.repeat(count).then(VI_INSERT); } else { return super.on(keyStroke); return EditorAction.MOVE_PREV_WORD_AT_END.repeat(count).then(VI_MOVE); } else { super.on(keyStroke);
@Override String execute(Editor editor, EditorBuffer buffer, int[] sequence, boolean flush) throws IOException { if (editor.isEmpty()) { editor.console.status = Console.CLOSING; return null; } else { if (editor.console.getMode() == Mode.EMACS) { return EditorAction.DELETE_PREV_CHAR.execute(editor, buffer, sequence, true); } else { return EditorAction.ENTER.execute(editor, buffer, sequence, true); } } } };
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { int pos = buffer.getCursor(); EditorAction.MOVE_NEXT_WORD_AT_BEGINNING.perform(editor, buffer); while (buffer.getCursor() > pos) { buffer.del(); } } };
@Override public EditorAction on(KeyStroke keyStroke) { switch (keyStroke.operation) { case VI_MOVEMENT_MODE: // ESC return VI_MOVE; case INTERRUPT: return EditorAction.INTERRUPT.then(VI_MOVE); default: return new EditorAction.ChangeChars(count, keyStroke.sequence[0]).then(VI_MOVE); } }
case BACKWARD_CHAR: if (to == null) { return EditorAction.LEFT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_PREV_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { return EditorAction.RIGHT.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_CHAR.repeat(count).then(VI_INSERT); } else if (to == 'y') { throw new UnsupportedOperationException("Not yet handled"); return EditorAction.MOVE_NEXT_WORD_AT_BEGINNING.repeat(count).then(VI_MOVE); } else if (to == 'd') { return EditorAction.DELETE_UNTIL_NEXT_WORD.repeat(count).then(VI_MOVE); } else if (to == 'c') { return EditorAction.DELETE_NEXT_WORD.repeat(count).then(VI_INSERT); } else { return super.on(keyStroke); return EditorAction.MOVE_PREV_WORD_AT_END.repeat(count).then(VI_MOVE); } else { super.on(keyStroke);
@Override void perform(Editor editor, EditorBuffer buffer) throws IOException { for (int i = 0;i < count;i++) { EditorAction.this.perform(editor, buffer); } } };
return VI_INSERT; case VI_INSERT_BEG: return EditorAction.MOVE_BEGINNING.then(VI_INSERT); case VI_INSERT_COMMENT: return EditorAction.INSERT_COMMENT; return EditorAction.MOVE_PREV_WORD_AT_BEGINNING; case VI_CHANGE_TO_EOL: return EMACS.then(EditorAction.DELETE_END).then(VI_INSERT); case VI_CHANGE_TO: return CHANGE_TO; return EMACS.then(EditorAction.RIGHT).then(VI_INSERT); case VI_BEGNNING_OF_LINE_OR_ARG_DIGIT: return EditorAction.MOVE_BEGINNING; return EditorAction.CHANGE_CASE; case VI_KILL_WHOLE_LINE: return EditorAction.DELETE_LINE.then(VI_INSERT); case VI_PUT: return EditorAction.PASTE_AFTER;