From: Stefan Monnier Date: Sat, 24 Sep 2022 14:38:09 +0000 (-0400) Subject: (event-start/end): Fix part of bug#52092 X-Git-Tag: emacs-29.0.90~1856^2~254 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c1cead89f5f230d9bd10da54f0e959d2570a037b;p=emacs.git (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. --- 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.