diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
commit | 650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch) | |
tree | 85d11f6437cde22f410c25e0e5f71a3131ebd07d /lisp/scroll-bar.el | |
parent | 8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff) | |
parent | 4b85ae6a24380fb67a3315eaec9233f17a872473 (diff) | |
download | emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2 emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip |
Merge 'master' into noverlay
Diffstat (limited to 'lisp/scroll-bar.el')
-rw-r--r-- | lisp/scroll-bar.el | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index 8f02f2f3e9d..5786a21e88e 100644 --- a/lisp/scroll-bar.el +++ b/lisp/scroll-bar.el @@ -1,6 +1,6 @@ -;;; scroll-bar.el --- window system-independent scroll bar support +;;; scroll-bar.el --- window system-independent scroll bar support -*- lexical-binding: t; -*- -;; Copyright (C) 1993-1995, 1999-2017 Free Software Foundation, Inc. +;; Copyright (C) 1993-1995, 1999-2022 Free Software Foundation, Inc. ;; Maintainer: emacs-devel@gnu.org ;; Keywords: hardware @@ -49,9 +49,7 @@ from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS \(buffer-size)) is the position in the current buffer corresponding to that scroll bar position." ;; We multiply before we divide to maintain precision. - ;; We use floating point because the product of a large buffer size - ;; with a large scroll bar portion can easily overflow a lisp int. - (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) + (truncate (* (car num-denom) whole) (cdr num-denom))) (defun scroll-bar-columns (side) "Return the width, measured in columns, of the vertical scrollbar on SIDE. @@ -133,12 +131,12 @@ Setting the variable with a customization buffer also takes effect." (define-minor-mode scroll-bar-mode "Toggle vertical scroll bars on all frames (Scroll Bar mode). -With a prefix argument ARG, enable Scroll Bar mode if ARG is -positive, and disable it otherwise. If called from Lisp, enable -the mode if ARG is omitted or nil. -This command applies to all frames that exist and frames to be -created in the future." +This command applies to all frames that exist, as well as new +frames to be created in the future. This is done by altering the +frame parameters, so if you (re-)set `default-frame-alist' after +toggling the scroll bars on or off with this command, the scroll +bars may reappear on new frames." :variable ((get-scroll-bar-mode) . (lambda (v) (set-scroll-bar-mode (if v (or previous-scroll-bar-mode @@ -152,9 +150,6 @@ created in the future." (define-minor-mode horizontal-scroll-bar-mode "Toggle horizontal scroll bars on all frames (Horizontal Scroll Bar mode). -With a prefix argument ARG, enable Horizontal Scroll Bar mode if -ARG is positive, and disable it otherwise. If called from Lisp, -enable the mode if ARG is omitted or nil. This command applies to all frames that exist and frames to be created in the future." @@ -260,14 +255,22 @@ EVENT should be a scroll bar click or drag event." (let* ((start-position (event-start event)) (window (nth 0 start-position)) (portion-whole (nth 2 start-position))) - (save-excursion - (with-current-buffer (window-buffer window) - ;; Calculate position relative to the accessible part of the buffer. - (goto-char (+ (point-min) - (scroll-bar-scale portion-whole - (- (point-max) (point-min))))) - (vertical-motion 0 window) - (set-window-start window (point)))))) + ;; With 'scroll-bar-adjust-thumb-portion' nil and 'portion-whole' + ;; indicating that the buffer is fully visible, do not scroll the + ;; window since that might make it impossible to scroll it back + ;; with GTK's thumb (Bug#32002). + (when (or scroll-bar-adjust-thumb-portion + (not (numberp (car portion-whole))) + (not (numberp (cdr portion-whole))) + (/= (car portion-whole) (cdr portion-whole))) + (save-excursion + (with-current-buffer (window-buffer window) + ;; Calculate position relative to the accessible part of the buffer. + (goto-char (+ (point-min) + (scroll-bar-scale portion-whole + (- (point-max) (point-min))))) + (vertical-motion 0 window) + (set-window-start window (point))))))) (defun scroll-bar-drag (event) "Scroll the window by dragging the scroll bar slider. |