boolean (@NotNull MouseEvent e) { if (!tweakSelectionEvent(e)) { return false; } int startSelectionOffset = getSelectionModel().getSelectionStart(); int startVisLine = offsetToVisualLine(startSelectionOffset); int endSelectionOffset = getSelectionModel().getSelectionEnd(); int endVisLine = offsetToVisualLine(endSelectionOffset - 1); int clickVisLine = yPositionToVisibleLine(e.getPoint().y); if (clickVisLine < startVisLine) { // Expand selection at backward direction. int startOffset = logicalPositionToOffset(visualToLogicalPosition(new VisualPosition(clickVisLine, 0))); getSelectionModel().setSelection(startOffset, endSelectionOffset); getCaretModel().moveToOffset(startOffset); } else if (clickVisLine > endVisLine) { // Expand selection at forward direction. int endLineOffset = EditorUtil.getVisualLineEndOffset(this, clickVisLine); getSelectionModel().setSelection(getSelectionModel().getSelectionStart(), endLineOffset); getCaretModel().moveToOffset(endLineOffset, true); } else if (startVisLine == endVisLine) { // Remove selection getSelectionModel().removeSelection(); } else { // Reduce selection in backward direction. if (getSelectionModel().getLeadSelectionOffset() == endSelectionOffset) { if (clickVisLine == startVisLine) { clickVisLine++; } int startOffset = logicalPositionToOffset(visualToLogicalPosition(new VisualPosition(clickVisLine, 0))); getSelectionModel().setSelection(startOffset, endSelectionOffset); getCaretModel().moveToOffset(startOffset); } else { // Reduce selection is forward direction. if (clickVisLine == endVisLine) { clickVisLine--; } int endLineOffset = EditorUtil.getVisualLineEndOffset(this, clickVisLine); getSelectionModel().setSelection(startSelectionOffset, endLineOffset); getCaretModel().moveToOffset(endLineOffset); } } e.consume(); return true; }