(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.
This commit is contained in:
Stefan Monnier 2022-09-24 10:38:09 -04:00
parent 0cc107ac09
commit c1cead89f5

View file

@ -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.