all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH v3 1/3] Improve interaction between mouse-drag-region and scroll-margin
@ 2021-09-25 19:00 Yuri D'Elia
  2021-09-25 19:00 ` [PATCH v3 2/3] Perform cleanup on errors in mouse-drag-track Yuri D'Elia
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Yuri D'Elia @ 2021-09-25 19:00 UTC (permalink / raw)
  To: emacs-devel; +Cc: Yuri D'Elia

* lisp/mouse.el (mouse-drag-track): Disable both scroll-margin and
auto-hscroll-mode in mouse-drag-region and do not re-enable them until
dragging is over, making selections work as expected when inside the
margins.

Since mouse-drag-region is initiated on the initial down-mouse event, we
_shouldn't_ scroll the point until up-mouse is finally received, as it
would otherwise interfere with the regular mouse-1 event. If the point
is moved on down-mouse an immediate motion event results, jump-starting
the drag.

Complicating things, as the tracking is done in a transient map, a
let-bound scroll-margin is not sufficient. We must save/restore its
value (as similarly done already for auto-hscroll-mode).

The point will still moved according to scroll-margin due to mouse-1,
but now it's done only when releasing the mouse button. Simply clicking
inside the scroll-margin region now behaves as expected.

This partially addresses Bug#42150 (previous discussion at Bug#9541).

Clicking inside the scroll-margin region still occasionally causes some
regions to be selected, although it doesn't cause the buffer to scroll
uncontrollably anymore.
---
 lisp/mouse.el | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 9f1417f42..a6c999594 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1578,8 +1578,7 @@ mouse-drag-track
   (mouse-minibuffer-check start-event)
   (setq mouse-selection-click-count-buffer (current-buffer))
   (deactivate-mark)
-  (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
-	 (start-posn (event-start start-event))
+  (let* ((start-posn (event-start start-event))
 	 (start-point (posn-point start-posn))
 	 (start-window (posn-window start-posn))
 	 (_ (with-current-buffer (window-buffer start-window)
@@ -1601,12 +1600,20 @@ mouse-drag-track
 		   ;; Don't count the mode line.
 		   (1- (nth 3 bounds))))
 	 (click-count (1- (event-click-count start-event)))
-	 ;; Suppress automatic hscrolling, because that is a nuisance
-	 ;; when setting point near the right fringe (but see below).
+         ;; Save original automatic scrolling behavior (see below).
 	 (auto-hscroll-mode-saved auto-hscroll-mode)
+	 (scroll-margin-saved scroll-margin)
          (old-track-mouse track-mouse))
 
     (setq mouse-selection-click-count click-count)
+
+    ;; Suppress automatic scrolling near the edges while tracking
+    ;; movement, as it interferes with the natural dragging behavior
+    ;; (point will unexpectedly be moved beneath the pointer, making
+    ;; selections in auto-scrolling margins impossible).
+    (setq auto-hscroll-mode nil)
+    (setq scroll-margin 0)
+
     ;; In case the down click is in the middle of some intangible text,
     ;; use the end of that text, and put it in START-POINT.
     (if (< (point) start-point)
@@ -1625,7 +1632,6 @@ mouse-drag-track
 
     (setf (terminal-parameter nil 'mouse-drag-start) start-event)
     (setq track-mouse t)
-    (setq auto-hscroll-mode nil)
 
     (set-transient-map
      (let ((map (make-sparse-keymap)))
@@ -1636,8 +1642,6 @@ mouse-drag-track
            (let* ((end (event-end event))
                   (end-point (posn-point end)))
              (unless (eq end-point start-point)
-               ;; As soon as the user moves, we can re-enable auto-hscroll.
-               (setq auto-hscroll-mode auto-hscroll-mode-saved)
                ;; And remember that we have moved, so mouse-set-region can know
                ;; its event is really a drag event.
                (setcar start-event 'mouse-movement))
@@ -1658,6 +1662,7 @@ mouse-drag-track
      t (lambda ()
          (setq track-mouse old-track-mouse)
          (setq auto-hscroll-mode auto-hscroll-mode-saved)
+         (setq scroll-margin scroll-margin-saved)
          ;; Don't deactivate the mark when the context menu was invoked
          ;; by down-mouse-3 immediately after down-mouse-1 and without
          ;; releasing the mouse button with mouse-1. This allows to use
-- 
2.33.0




^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-29 20:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-25 19:00 [PATCH v3 1/3] Improve interaction between mouse-drag-region and scroll-margin Yuri D'Elia
2021-09-25 19:00 ` [PATCH v3 2/3] Perform cleanup on errors in mouse-drag-track Yuri D'Elia
2021-09-25 19:00 ` [PATCH v3 3/3] Document the improved scroll-margin behavior Yuri D'Elia
2021-09-26 12:33 ` [PATCH v3 1/3] Improve interaction between mouse-drag-region and scroll-margin Yuri D'Elia
2021-09-29 10:08 ` Yuri D'Elia
2021-09-29 15:54   ` Lars Ingebrigtsen
2021-09-29 20:41     ` Yuri D'Elia

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.