[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2fba71cf1f: Fix handling double-click-time nil or t
From: |
Lars Ingebrigtsen |
Subject: |
master 2fba71cf1f: Fix handling double-click-time nil or t |
Date: |
Mon, 2 May 2022 06:05:07 -0400 (EDT) |
branch: master
commit 2fba71cf1fadc9d681e6be250d152cc156bf6a00
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Fix handling double-click-time nil or t
* lisp/mouse.el (mouse-double-click-time): New function to always
return a number for `double-click-time'.
* lisp/emulation/viper-mous.el (viper-multiclick-timeout):
* lisp/foldout.el (foldout-mouse-swallow-events):
* lisp/help.el (help--read-key-sequence):
* lisp/org/org-mouse.el (org-mouse-show-context-menu): Use
'mouse-double-click-time' instead of 'double-click-time'.
* src/keyboard.c (syms_of_keyboard): Mention
'mouse-double-click-time' in doc string of 'double-click-time'.
* test/lisp/mouse-tests.el (mouse-test-mouse-double-click-time):
New test.
---
lisp/emulation/viper-mous.el | 4 ++--
lisp/foldout.el | 2 +-
lisp/help.el | 2 +-
lisp/mouse.el | 11 +++++++++++
lisp/org/org-mouse.el | 2 +-
src/keyboard.c | 5 ++++-
test/lisp/mouse-tests.el | 14 ++++++++++++++
7 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/lisp/emulation/viper-mous.el b/lisp/emulation/viper-mous.el
index 7581ece214..1a90cab767 100644
--- a/lisp/emulation/viper-mous.el
+++ b/lisp/emulation/viper-mous.el
@@ -62,8 +62,8 @@ or a triple-click."
;; time interval in millisecond within which successive clicks are
;; considered related
(defcustom viper-multiclick-timeout (if (viper-window-display-p)
- double-click-time
- 500)
+ (mouse-double-click-time)
+ 500)
"Time interval in milliseconds for mouse clicks to be considered related."
:type 'integer)
diff --git a/lisp/foldout.el b/lisp/foldout.el
index 4b192a7b6a..e00fb40e3c 100644
--- a/lisp/foldout.el
+++ b/lisp/foldout.el
@@ -473,7 +473,7 @@ What happens depends on the number of mouse clicks:-
"Swallow intervening mouse events so we only get the final click-count.
Signal an error if the final event isn't the same type as the first one."
(let ((initial-event-type (event-basic-type event)))
- (while (null (sit-for (/ double-click-time 1000.0) 'nodisplay))
+ (while (null (sit-for (/ (mouse-double-click-time) 1000.0) 'nodisplay))
(setq event (read--potential-mouse-event)))
(or (eq initial-event-type (event-basic-type event))
(error "")))
diff --git a/lisp/help.el b/lisp/help.el
index fe999de638..3c0370fee1 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -867,7 +867,7 @@ with `mouse-movement' events."
(memq 'down last-modifiers)
;; After a click, see if a double click is on the way.
(and (memq 'click last-modifiers)
- (not (sit-for (/ double-click-time 1000.0) t))))
+ (not (sit-for (/ (mouse-double-click-time) 1000.0) t))))
(let* ((seq (read-key-sequence "\
Describe the following key, mouse click, or menu item: "
nil nil 'can-return-switch-frame))
diff --git a/lisp/mouse.el b/lisp/mouse.el
index c08ecaf334..0446bc6dd8 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -167,6 +167,17 @@ Expects to be bound to `(double-)mouse-1' in
`key-translation-map'."
(define-key key-translation-map [double-mouse-1]
#'mouse--click-1-maybe-follows-link)
+(defun mouse-double-click-time ()
+ "Return a number for `double-click-time'.
+In contrast to using the `double-click-time' variable directly,
+which could be set to nil or t, this function is guaranteed to
+always return a positive integer or zero."
+ (let ((ct double-click-time))
+ (cond ((eq ct t) 10000) ; arbitrary number useful for sit-for
+ ((eq ct nil) 0)
+ ((and (numberp ct) (> ct 0)) ct)
+ (t 0))))
+
;; Provide a mode-specific menu on a mouse button.
diff --git a/lisp/org/org-mouse.el b/lisp/org/org-mouse.el
index 20c20acc32..a590ff87f2 100644
--- a/lisp/org/org-mouse.el
+++ b/lisp/org/org-mouse.el
@@ -208,7 +208,7 @@ this function is called. Otherwise, the current major mode
menu is used."
(interactive "@e \nP")
(if (and (= (event-click-count event) 1)
(or (not mark-active)
- (sit-for (/ double-click-time 1000.0))))
+ (sit-for (/ (mouse-double-click-time) 1000.0))))
(progn
(select-window (posn-window (event-start event)))
(when (not (org-mouse-mark-active))
diff --git a/src/keyboard.c b/src/keyboard.c
index 69e741070c..70908120cb 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -12434,7 +12434,10 @@ Polling is automatically disabled in all other cases.
*/);
doc: /* Maximum time between mouse clicks to make a double-click.
Measured in milliseconds. The value nil means disable double-click
recognition; t means double-clicks have no time limit and are detected
-by position only. */);
+by position only.
+
+In Lisp, you might want to use `mouse-double-click-time' instead of
+reading the value of this variable directly. */);
Vdouble_click_time = make_fixnum (500);
DEFVAR_INT ("double-click-fuzz", double_click_fuzz,
diff --git a/test/lisp/mouse-tests.el b/test/lisp/mouse-tests.el
index 1be32006a1..03ecbc1985 100644
--- a/test/lisp/mouse-tests.el
+++ b/test/lisp/mouse-tests.el
@@ -25,6 +25,20 @@
;;; Code:
+(ert-deftest mouse-test-mouse-double-click-time ()
+ (let ((double-click-time 500))
+ (should (= (mouse-double-click-time) 500)))
+ (let ((double-click-time 0))
+ (should (= (mouse-double-click-time) 0)))
+ (let ((double-click-time -500))
+ (should (= (mouse-double-click-time) 0)))
+ (let ((double-click-time nil))
+ (should (= (mouse-double-click-time) 0)))
+ (let ((double-click-time t))
+ (should (numberp (mouse-double-click-time))))
+ (let ((double-click-time '(invalid)))
+ (should (= (mouse-double-click-time) 0))))
+
(ert-deftest bug23288-use-return-value ()
"If `mouse-on-link-p' returns a string, its first character is used."
(cl-letf ((unread-command-events '((down-mouse-1 nil 1) (mouse-1 nil 1)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 2fba71cf1f: Fix handling double-click-time nil or t,
Lars Ingebrigtsen <=