mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-26 10:49:33 +00:00
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.
This commit is contained in:
parent
f7a6dd4fcc
commit
2fba71cf1f
@ -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)
|
||||
|
||||
|
@ -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 "")))
|
||||
|
@ -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))
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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,
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user