private Map<Integer, Couple<Integer>> createVirtualSelectionMap( int startVisualLine, int endVisualLine) { HashMap<Integer, Couple<Integer>> map = new HashMap<Integer, Couple<Integer>>(); for (Caret caret : myEditor.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, Couple.of(selectionStart.column, selectionEnd.column)); } } } } return map; }