void (@NotNull String key, int caretAt) { int templateStart = caretAt - key.length(); myEditor.getDocument().deleteString(templateStart, caretAt); myEditor.getCaretModel().moveToOffset(templateStart); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); myEditor.getSelectionModel().removeSelection(); }