int (@NotNull Editor editor) { SelectionModel selectionModel = editor.getSelectionModel(); return selectionModel.hasSelection() ? selectionModel.getSelectionStart() : Math.max(editor.getCaretModel().getOffset() - 1, 0); }