void (@NotNull AnActionEvent e, boolean state) { final EditorEx editor = getEditor(e); final SelectionModel selectionModel = editor.getSelectionModel(); final CaretModel caretModel = editor.getCaretModel(); if (state) { caretModel.removeSecondaryCarets(); boolean hasSelection = selectionModel.hasSelection(); int selStart = selectionModel.getSelectionStart(); int selEnd = selectionModel.getSelectionEnd(); LogicalPosition blockStart, blockEnd; if (caretModel.supportsMultipleCarets()) { LogicalPosition logicalSelStart = editor.offsetToLogicalPosition(selStart); LogicalPosition logicalSelEnd = editor.offsetToLogicalPosition(selEnd); int caretOffset = caretModel.getOffset(); blockStart = selStart == caretOffset ? logicalSelEnd : logicalSelStart; blockEnd = selStart == caretOffset ? logicalSelStart : logicalSelEnd; } else { blockStart = selStart == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selStart); blockEnd = selEnd == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selEnd); } editor.setColumnMode(true); if (hasSelection) { selectionModel.setBlockSelection(blockStart, blockEnd); } else { selectionModel.removeSelection(); } } else { boolean hasSelection = false; int selStart = 0; int selEnd = 0; if (caretModel.supportsMultipleCarets()) { hasSelection = true; List<Caret> allCarets = caretModel.getAllCarets(); Caret fromCaret = allCarets.get(0); Caret toCaret = allCarets.get(allCarets.size() - 1); if (fromCaret == caretModel.getPrimaryCaret()) { Caret tmp = fromCaret; fromCaret = toCaret; toCaret = tmp; } selStart = fromCaret.getLeadSelectionOffset(); selEnd = toCaret.getSelectionStart() == toCaret.getLeadSelectionOffset() ? toCaret.getSelectionEnd() : toCaret.getSelectionStart(); } editor.setColumnMode(false); caretModel.removeSecondaryCarets(); if (hasSelection) { selectionModel.setSelection(selStart, selEnd); } else { selectionModel.removeSelection(); } } }