From: Yuri D'Elia <wavexx@thregr.org>
To: emacs-devel@gnu.org
Cc: Yuri D'Elia <wavexx@thregr.org>
Subject: [PATCH] Improve interaction between mouse-drag-region and scroll-margin
Date: Sat, 25 Sep 2021 18:09:22 +0200 [thread overview]
Message-ID: <20210925160922.114811-1-wavexx@thregr.org> (raw)
* 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 done already for auto-hscroll-margin.
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.
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
next reply other threads:[~2021-09-25 16:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-25 16:09 Yuri D'Elia [this message]
2021-09-25 16:17 ` [PATCH] Improve interaction between mouse-drag-region and scroll-margin Eli Zaretskii
2021-09-25 16:31 ` Yuri D'Elia
2021-09-25 16:41 ` Eli Zaretskii
2021-09-25 17:03 ` Yuri D'Elia
2021-09-25 17:19 ` Eli Zaretskii
2021-09-25 17:31 ` Yuri D'Elia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210925160922.114811-1-wavexx@thregr.org \
--to=wavexx@thregr.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.