summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-09-24 10:38:09 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2022-09-24 10:38:09 -0400
commitc1cead89f5f230d9bd10da54f0e959d2570a037b (patch)
tree0642ca9350271bca7960ca080dae71799e123451
parent0cc107ac090a67a01e237d48ee5c158eb95f6337 (diff)
downloademacs-c1cead89f5f230d9bd10da54f0e959d2570a037b.tar.gz
emacs-c1cead89f5f230d9bd10da54f0e959d2570a037b.tar.bz2
emacs-c1cead89f5f230d9bd10da54f0e959d2570a037b.zip
(event-start/end): Fix part of bug#52092
When synthesizing a posn for keyboard events, make sure the `posn-point` i the same as `point`. * lisp/subr.el (event--posn-at-point): New function. (event-start, event-end): Use it.
-rw-r--r--lisp/subr.el25
1 files changed, 17 insertions, 8 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 59f9308f31e..26fba4771bc 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1562,6 +1562,21 @@ in the current Emacs session, then this function may return nil."
;; is this really correct? maybe remove mouse-movement?
(memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement)))
+(defun event--posn-at-point ()
+ ;; Use `window-point' for the case when the current buffer
+ ;; is temporarily switched to some other buffer (bug#50256)
+ (let* ((pos (window-point))
+ (posn (posn-at-point pos)))
+ (if (null posn) ;; `pos' is "out of sight".
+ (list (selected-window) pos '(0 . 0) 0)
+ ;; If `pos' is inside a chunk of text hidden by an `invisible'
+ ;; or `display' property, `posn-at-point' returns the position
+ ;; that *is* visible, whereas `event--posn-at-point' is used
+ ;; when we have a keyboard event, whose position is `point' even
+ ;; if that position is invisible.
+ (setf (nth 5 posn) pos)
+ posn)))
+
(defun event-start (event)
"Return the starting position of EVENT.
EVENT should be a mouse click, drag, or key press event. If
@@ -1588,10 +1603,7 @@ nil or (STRING . POSITION)'.
For more information, see Info node `(elisp)Click Events'."
(or (and (consp event) (nth 1 event))
- ;; Use `window-point' for the case when the current buffer
- ;; is temporarily switched to some other buffer (bug#50256)
- (posn-at-point (window-point))
- (list (selected-window) (window-point) '(0 . 0) 0)))
+ (event--posn-at-point)))
(defun event-end (event)
"Return the ending position of EVENT.
@@ -1599,10 +1611,7 @@ EVENT should be a click, drag, or key press event.
See `event-start' for a description of the value returned."
(or (and (consp event) (nth (if (consp (nth 2 event)) 2 1) event))
- ;; Use `window-point' for the case when the current buffer
- ;; is temporarily switched to some other buffer (bug#50256)
- (posn-at-point (window-point))
- (list (selected-window) (window-point) '(0 . 0) 0)))
+ (event--posn-at-point)))
(defsubst event-click-count (event)
"Return the multi-click count of EVENT, a click or drag event.