summaryrefslogtreecommitdiff
path: root/lisp/mouse.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2019-11-30 11:37:04 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2019-11-30 22:43:00 +0100
commit293eb3259883c0b8465926a850b9ca7131e70074 (patch)
tree876864be00f489aa63cc4f5df3e794344b4043df /lisp/mouse.el
parentdfbbbf319e4e357c82a79944090c949f3c5299c3 (diff)
downloademacs-293eb3259883c0b8465926a850b9ca7131e70074.tar.gz
emacs-293eb3259883c0b8465926a850b9ca7131e70074.tar.bz2
emacs-293eb3259883c0b8465926a850b9ca7131e70074.zip
Improved mouse rectangle selection robustness (bug#38013)
Make the rectangular selection work better with display-line-numbers-mode and side-by-side windows. Also make the mouse track the text cursor in a consistent way. * lisp/mouse.el (mouse--rectangle-track-cursor): Added constant. (mouse-drag-region-rectangle): Take the line-number width into account, and use window-relative columns. Track either the cursor or rectangle corner with more care.
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r--lisp/mouse.el18
1 files changed, 13 insertions, 5 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index f076e90bd93..bc05a35009e 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1964,6 +1964,10 @@ When there is no region, this function does nothing."
(move-overlay mouse-secondary-overlay (region-beginning) (region-end))))
+(defconst mouse--rectangle-track-cursor t
+ "Whether the mouse tracks the cursor when selecting a rectangle.
+If nil, the mouse tracks the rectangle corner instead.")
+
(defun mouse-drag-region-rectangle (start-event)
"Set the region to the rectangle that the mouse is dragged over.
This must be bound to a button-down mouse event."
@@ -1980,6 +1984,7 @@ This must be bound to a button-down mouse event."
(bottom (if (window-minibuffer-p start-window)
(nth 3 bounds)
(1- (nth 3 bounds))))
+ (extra-margin (round (line-number-display-width 'columns)))
(dragged nil)
(old-track-mouse track-mouse)
(old-mouse-fine-grained-tracking mouse-fine-grained-tracking)
@@ -1988,8 +1993,9 @@ This must be bound to a button-down mouse event."
(adjusted-col (lambda (col)
(if (eq (current-bidi-paragraph-direction)
'right-to-left)
- (- (frame-text-cols) col -1)
- col)))
+ (- (window-width) col extra-margin
+ (if mouse--rectangle-track-cursor 1 -1))
+ (- col extra-margin))))
(map (make-sparse-keymap)))
(define-key map [switch-frame] #'ignore)
(define-key map [select-window] #'ignore)
@@ -2018,13 +2024,15 @@ This must be bound to a button-down mouse event."
(hscroll (if (window-live-p window)
(window-hscroll window)
0))
- (mouse-pos (mouse-position))
- (mouse-col (+ (cadr mouse-pos) hscroll))
- (mouse-row (cddr mouse-pos))
+ (mouse-row (cddr (mouse-position)))
+ (mouse-col (+ (car (posn-col-row posn)) hscroll
+ (if mouse--rectangle-track-cursor 0 1)))
(set-col (lambda ()
(if (or (eolp) (eq (following-char) ?\t))
(rectangle--col-pos
(funcall adjusted-col mouse-col) 'point)
+ (unless mouse--rectangle-track-cursor
+ (forward-char))
(rectangle--reset-point-crutches)))))
(if (and (eq window start-window)
mouse-row