aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Stephani2016-05-10 23:23:26 +0200
committerPhilipp Stephani2016-05-20 19:47:58 +0200
commitf2b7a432687d6d561162774b8f3dc558903c796f (patch)
tree567404b57c4aafffbdf42353606c1e5f7d403aaa
parent65e38569e5eca8e4e8a0e38391c07e3862e78cb7 (diff)
downloademacs-f2b7a432687d6d561162774b8f3dc558903c796f.tar.gz
emacs-f2b7a432687d6d561162774b8f3dc558903c796f.zip
Fix handling of ‘mouse-on-link-p’.
If ‘mouse-on-link-p’ returns a string or vector, the first element is to be used as new event. Translation to ‘mouse-2’ should only happen if the return value is not a string or vector. See docstring of ‘mouse-on-link-p’ and Bug#23288. * lisp/mouse.el (mouse--down-1-maybe-follows-link): Process return value of ‘mouse-on-link-p’ according to documentation. * test/lisp/mouse-tests.el (bug23288-use-return-value) (bug23288-translate-to-mouse-2): Tests for Bug#23288.
-rw-r--r--lisp/mouse.el67
-rw-r--r--test/lisp/mouse-tests.el48
2 files changed, 86 insertions, 29 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index e5e111054e1..3e3708a2e0d 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -97,35 +97,44 @@ Expects to be bound to `down-mouse-1' in `key-translation-map'."
97 (when (and mouse-1-click-follows-link 97 (when (and mouse-1-click-follows-link
98 (eq (if (eq mouse-1-click-follows-link 'double) 98 (eq (if (eq mouse-1-click-follows-link 'double)
99 'double-down-mouse-1 'down-mouse-1) 99 'double-down-mouse-1 'down-mouse-1)
100 (car-safe last-input-event)) 100 (car-safe last-input-event)))
101 (mouse-on-link-p (event-start last-input-event)) 101 (let ((action (mouse-on-link-p (event-start last-input-event))))
102 (or mouse-1-click-in-non-selected-windows 102 (when (and action
103 (eq (selected-window) 103 (or mouse-1-click-in-non-selected-windows
104 (posn-window (event-start last-input-event))))) 104 (eq (selected-window)
105 (let ((timedout 105 (posn-window (event-start last-input-event)))))
106 (sit-for (if (numberp mouse-1-click-follows-link) 106 (let ((timedout
107 (/ (abs mouse-1-click-follows-link) 1000.0) 107 (sit-for (if (numberp mouse-1-click-follows-link)
108 0)))) 108 (/ (abs mouse-1-click-follows-link) 1000.0)
109 (if (if (and (numberp mouse-1-click-follows-link) 109 0))))
110 (>= mouse-1-click-follows-link 0)) 110 (if (if (and (numberp mouse-1-click-follows-link)
111 timedout (not timedout)) 111 (>= mouse-1-click-follows-link 0))
112 nil 112 timedout (not timedout))
113 113 nil
114 (let ((event (read-key))) ;Use read-key so it works for xterm-mouse-mode! 114 ;; Use read-key so it works for xterm-mouse-mode!
115 (if (eq (car-safe event) (if (eq mouse-1-click-follows-link 'double) 115 (let ((event (read-key)))
116 'double-mouse-1 'mouse-1)) 116 (if (eq (car-safe event)
117 ;; Turn the mouse-1 into a mouse-2 to follow links. 117 (if (eq mouse-1-click-follows-link 'double)
118 (let ((newup (if (eq mouse-1-click-follows-link 'double) 118 'double-mouse-1 'mouse-1))
119 'double-mouse-2 'mouse-2))) 119 (progn
120 ;; If mouse-2 has never been done by the user, it doesn't have 120 ;; Turn the mouse-1 into a mouse-2 to follow links,
121 ;; the necessary property to be interpreted correctly. 121 ;; but only if ‘mouse-on-link-p’ hasn’t returned a
122 (unless (get newup 'event-kind) 122 ;; string or vector (see its docstring).
123 (put newup 'event-kind (get (car event) 'event-kind))) 123 (if (or (stringp action) (vectorp action))
124 (push (cons newup (cdr event)) unread-command-events) 124 (push (aref action 0) unread-command-events)
125 ;; Don't change the down event, only the up-event (bug#18212). 125 (let ((newup (if (eq mouse-1-click-follows-link 'double)
126 nil) 126 'double-mouse-2 'mouse-2)))
127 (push event unread-command-events) 127 ;; If mouse-2 has never been done by the user, it
128 nil)))))) 128 ;; doesn't have the necessary property to be
129 ;; interpreted correctly.
130 (unless (get newup 'event-kind)
131 (put newup 'event-kind (get (car event) 'event-kind)))
132 (push (cons newup (cdr event)) unread-command-events)))
133 ;; Don't change the down event, only the up-event
134 ;; (bug#18212).
135 nil)
136 (push event unread-command-events)
137 nil))))))))
129 138
130(define-key key-translation-map [down-mouse-1] 139(define-key key-translation-map [down-mouse-1]
131 #'mouse--down-1-maybe-follows-link) 140 #'mouse--down-1-maybe-follows-link)
diff --git a/test/lisp/mouse-tests.el b/test/lisp/mouse-tests.el
new file mode 100644
index 00000000000..21abf38798d
--- /dev/null
+++ b/test/lisp/mouse-tests.el
@@ -0,0 +1,48 @@
1;;; mouse-tests.el --- unit tests for mouse.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Author: Philipp Stephani <phst@google.com>
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;; Unit tests for lisp/mouse.el.
23
24;;; Code:
25
26(ert-deftest bug23288-use-return-value ()
27 "If ‘mouse-on-link-p’ returns a string, its first character is
28used."
29 (cl-letf ((last-input-event '(down-mouse-1 nil 1))
30 (unread-command-events '((mouse-1 nil 1)))
31 (mouse-1-click-follows-link t)
32 (mouse-1-click-in-non-selected-windows t)
33 ((symbol-function 'mouse-on-link-p) (lambda (_pos) "abc")))
34 (should-not (mouse--down-1-maybe-follows-link))
35 (should (equal unread-command-events '(?a)))))
36
37(ert-deftest bug23288-translate-to-mouse-2 ()
38 "If ‘mouse-on-link-p’ doesn’t return a string or vector,
39translate ‘mouse-1’ events into ‘mouse-2’ events."
40 (cl-letf ((last-input-event '(down-mouse-1 nil 1))
41 (unread-command-events '((mouse-1 nil 1)))
42 (mouse-1-click-follows-link t)
43 (mouse-1-click-in-non-selected-windows t)
44 ((symbol-function 'mouse-on-link-p) (lambda (_pos) t)))
45 (should-not (mouse--down-1-maybe-follows-link))
46 (should (equal unread-command-events '((mouse-2 nil 1))))))
47
48;;; mouse-tests.el ends here