void (MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { return; } Rectangle rect = getScrollingModel().getVisibleArea(); int dx = 0; int x = e.getX(); if (e.getSource() == myGutterComponent) { x = 0; } if (x < rect.x) { dx = x - rect.x; } else { if (x > rect.x + rect.width) { dx = x - rect.x - rect.width; } } int dy = 0; int y = e.getY(); if (y < rect.y) { dy = y - rect.y; } else { if (y > rect.y + rect.height) { dy = y - rect.y - rect.height; } } if (dx == 0 && dy == 0) { myScrollingTimer.stop(); SelectionModel selectionModel = getSelectionModel(); int oldSelectionStart = selectionModel.getLeadSelectionOffset(); int oldCaretOffset = getCaretModel().getOffset(); LogicalPosition oldLogicalCaret = getCaretModel().getLogicalPosition(); moveCaretToScreenPos(x, y); getScrollingModel().scrollToCaret(ScrollType.RELATIVE); int newCaretOffset = getCaretModel().getOffset(); int caretShift = newCaretOffset - mySavedSelectionStart; if (myMousePressedEvent != null && getMouseEventArea(myMousePressedEvent) != EditorMouseEventArea.EDITING_AREA && getMouseEventArea(myMousePressedEvent) != EditorMouseEventArea.LINE_NUMBERS_AREA) { selectionModel.setSelection(oldSelectionStart, newCaretOffset); } else { if (isColumnMode()) { final LogicalPosition blockStart = selectionModel.hasBlockSelection() ? selectionModel.getBlockStart() : oldLogicalCaret; selectionModel.setBlockSelection(blockStart, getCaretModel().getLogicalPosition()); } else { if (getMouseSelectionState() != MOUSE_SELECTION_STATE_NONE) { if (caretShift < 0) { int newSelection = newCaretOffset; if (getMouseSelectionState() == MOUSE_SELECTION_STATE_WORD_SELECTED) { newSelection = mySelectionModel.getWordAtCaretStart(); } else { if (getMouseSelectionState() == MOUSE_SELECTION_STATE_LINE_SELECTED) { newSelection = logicalPositionToOffset( visualToLogicalPosition(new VisualPosition(getCaretModel().getVisualPosition().line, 0))); } } if (newSelection < 0) newSelection = newCaretOffset; selectionModel.setSelection(mySavedSelectionEnd, newSelection); getCaretModel().moveToOffset(newSelection); } else { int newSelection = newCaretOffset; if (getMouseSelectionState() == MOUSE_SELECTION_STATE_WORD_SELECTED) { newSelection = mySelectionModel.getWordAtCaretEnd(); } else { if (getMouseSelectionState() == MOUSE_SELECTION_STATE_LINE_SELECTED) { newSelection = logicalPositionToOffset( visualToLogicalPosition(new VisualPosition(getCaretModel().getVisualPosition().line + 1, 0))); } } if (newSelection < 0) newSelection = newCaretOffset; selectionModel.setSelection(mySavedSelectionStart, newSelection); getCaretModel().moveToOffset(newSelection); } return; } if (!myMousePressedInsideSelection) { selectionModel.setSelection(oldSelectionStart, newCaretOffset); } else { if (caretShift != 0) { if (myMousePressedEvent != null) { if (mySettings.isDndEnabled()) { boolean isCopy = isControlKeyDown(e) || isViewer() || !getDocument().isWritable(); mySavedCaretOffsetForDNDUndoHack = oldCaretOffset; getContentComponent().getTransferHandler().exportAsDrag(getContentComponent(), e, isCopy ? TransferHandler.COPY : TransferHandler.MOVE); } else { selectionModel.removeSelection(); } myMousePressedEvent = null; } } } } } } else { myScrollingTimer.start(dx, dy); } }