Fix mouse dragging of words and lines (Bug#6840).

* mouse.el (mouse--drag-set-mark-and-point): New function.
(mouse-drag-track): Use LOCATION arg to push-mark.  Use
mouse--drag-set-mark-and-point to take click-count into
consideration when updating point and mark (Bug#6840).
This commit is contained in:
Chong Yidong 2010-08-15 22:08:01 -04:00
parent 4e815860f5
commit 6d3e82d2d6
2 changed files with 29 additions and 14 deletions

View file

@ -1,3 +1,10 @@
2010-08-15 Chong Yidong <cyd@stupidchicken.com>
* mouse.el (mouse--drag-set-mark-and-point): New function.
(mouse-drag-track): Use LOCATION arg to push-mark. Use
mouse--drag-set-mark-and-point to take click-count into
consideration when updating point and mark (Bug#6840).
2010-08-15 Chong Yidong <cyd@stupidchicken.com> 2010-08-15 Chong Yidong <cyd@stupidchicken.com>
* progmodes/compile.el (compilation-error-regexp-alist-alist): * progmodes/compile.el (compilation-error-regexp-alist-alist):

View file

@ -954,8 +954,7 @@ DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
'(only) '(only)
(cons 'only transient-mark-mode))) (cons 'only transient-mark-mode)))
(let ((range (mouse-start-end start-point start-point click-count))) (let ((range (mouse-start-end start-point start-point click-count)))
(goto-char (nth 0 range)) (push-mark (nth 0 range) t t)
(push-mark nil t t)
(goto-char (nth 1 range))) (goto-char (nth 1 range)))
;; Track the mouse until we get a non-movement event. ;; Track the mouse until we get a non-movement event.
@ -974,14 +973,8 @@ DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
end-point (posn-point end)) end-point (posn-point end))
(if (and (eq (posn-window end) start-window) (if (and (eq (posn-window end) start-window)
(integer-or-marker-p end-point)) (integer-or-marker-p end-point))
;; If moving in the original window, move point by going (mouse--drag-set-mark-and-point start-point
;; to start first, so that if end is in intangible text, end-point click-count)
;; point jumps away from start. Don't do it if
;; start=end, or a single click would select a region if
;; it's on intangible text.
(unless (= start-point end-point)
(goto-char start-point)
(goto-char end-point))
(let ((mouse-row (cdr (cdr (mouse-position))))) (let ((mouse-row (cdr (cdr (mouse-position)))))
(cond (cond
((null mouse-row)) ((null mouse-row))
@ -999,8 +992,9 @@ DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
(eq (posn-window end) start-window) (eq (posn-window end) start-window)
(integer-or-marker-p end-point) (integer-or-marker-p end-point)
(/= start-point end-point)) (/= start-point end-point))
(goto-char start-point) (mouse--drag-set-mark-and-point start-point
(goto-char end-point)) end-point click-count))
;; Find its binding. ;; Find its binding.
(let* ((fun (key-binding (vector (car event)))) (let* ((fun (key-binding (vector (car event))))
(do-multi-click (and (> (event-click-count event) 0) (do-multi-click (and (> (event-click-count event) 0)
@ -1051,6 +1045,21 @@ DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
(put 'mouse-2 'event-kind 'mouse-click))) (put 'mouse-2 'event-kind 'mouse-click)))
(push event unread-command-events))))))) (push event unread-command-events)))))))
(defun mouse--drag-set-mark-and-point (start click click-count)
(let* ((range (mouse-start-end start click click-count))
(beg (nth 0 range))
(end (nth 1 range)))
(cond ((eq (mark) beg)
(goto-char end))
((eq (mark) end)
(goto-char beg))
((< click (mark))
(set-mark end)
(goto-char beg))
(t
(set-mark beg)
(goto-char end)))))
(defun mouse--remap-link-click-p (start-event end-event) (defun mouse--remap-link-click-p (start-event end-event)
(or (and (eq mouse-1-click-follows-link 'double) (or (and (eq mouse-1-click-follows-link 'double)
(= (event-click-count start-event) 2)) (= (event-click-count start-event) 2))
@ -1166,8 +1175,7 @@ If MODE is 2 then do the same for lines."
((= mode 2) ((= mode 2)
(list (save-excursion (list (save-excursion
(goto-char start) (goto-char start)
(beginning-of-line 1) (line-beginning-position 1))
(point))
(save-excursion (save-excursion
(goto-char end) (goto-char end)
(forward-line 1) (forward-line 1)