From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri D'Elia Newsgroups: gmane.emacs.devel Subject: [PATCH] Improve interaction between mouse-drag-region and scroll-margin Date: Sat, 25 Sep 2021 18:09:22 +0200 Message-ID: <20210925160922.114811-1-wavexx@thregr.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36104"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuri D'Elia To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 25 18:11:16 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUAGh-0009HM-Mc for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Sep 2021 18:11:15 +0200 Original-Received: from localhost ([::1]:35794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUAGg-00082C-ND for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Sep 2021 12:11:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUAF2-0005rs-PP for emacs-devel@gnu.org; Sat, 25 Sep 2021 12:09:32 -0400 Original-Received: from erc.thregr.org ([2001:41c9:1:41f::63]:48428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUAF0-000227-DV for emacs-devel@gnu.org; Sat, 25 Sep 2021 12:09:32 -0400 Original-Received: from [212.27.194.162] (helo=localhost) by erc.thregr.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) id 1mUAEw-000LgG-Sr (envelope-from ); Sat, 25 Sep 2021 18:09:26 +0200 X-Mailer: git-send-email 2.33.0 Received-SPF: pass client-ip=2001:41c9:1:41f::63; envelope-from=wavexx@thregr.org; helo=erc.thregr.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275458 Archived-At: * 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