Int2ObjectMap<IntPair> (Editor editor, int startVisualLine, int endVisualLine) { Int2ObjectMap<IntPair> map = new Int2ObjectOpenHashMap<>(); for (Caret caret : editor.getCaretModel().getAllCarets()) { if (caret.hasSelection()) { VisualPosition selectionStart = caret.getSelectionStartPosition(); VisualPosition selectionEnd = caret.getSelectionEndPosition(); if (selectionStart.line == selectionEnd.line) { int line = selectionStart.line; if (line >= startVisualLine && line <= endVisualLine) { map.put(line, new IntPair(selectionStart.column, selectionEnd.column)); } } } } return map; }