void (@NotNull Editor editor, @NotNull Runnable runnable) { int offset = editor.getCaretModel().getOffset(); int selectionStart = editor.getSelectionModel().getSelectionStart(); int selectionEnd = editor.getSelectionModel().getSelectionEnd(); runnable.run(); setCaretState(editor, offset, selectionStart, selectionEnd); }