From 0e9cee2bf5d97a23c47d99ffc47396dcd3bd50ee Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Thu, 28 Aug 2025 14:13:24 -0400 Subject: Ignore keymaps at point for positions outside the buffer Correct a few edge cases where we used the keymaps at point when looking up keymaps for an event position which is outside the current buffer. Namely: - Clicking on a part of the mode line which is after the end of mode-line-format produces an event with non-nil posn-area but nil posn-string. - Even if posn-string doesn't have a local keymap, we should still ignore the keymaps at point if posn-string is non-nil. * src/keymap.c (Fcurrent_active_maps): Ignore keymaps at point for more positions outside the buffer. (bug#76620) --- src/keymap.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/keymap.c b/src/keymap.c index 2c250578b00..295b209f06b 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -1735,11 +1735,20 @@ means to return the active maps for that window's buffer. */) } } - /* If on a mode line string with a local keymap, - or for a click on a string, i.e. overlay string or a - string displayed via the `display' property, - consider `local-map' and `keymap' properties of - that string. */ + Lisp_Object pos_area = POSN_POSN (position); + if (EQ (pos_area, Qmode_line) || EQ (pos_area, Qheader_line)) + { + /* For clicks on mode line or header line, ignore the maps + we found at POSITION, because properties at point are + not relevant in that case. */ + local_map = Qnil; + keymap = Qnil; + } + + /* If on a mode line string with a local keymap, or for a + click on a string, i.e. overlay string or a string + displayed via the `display' property, consider only the + `local-map' and `keymap' properties of that string. */ if (CONSP (string) && STRINGP (XCAR (string))) { @@ -1749,23 +1758,8 @@ means to return the active maps for that window's buffer. */) && XFIXNUM (pos) >= 0 && XFIXNUM (pos) < SCHARS (string)) { - Lisp_Object map = Fget_text_property (pos, Qlocal_map, - string); - Lisp_Object pos_area = POSN_POSN (position); - /* For clicks on mode line or header line, override - the maps we found at POSITION unconditionally, even - if the corresponding properties of the mode- or - header-line string are nil, because propertries at - point are not relevant in that case. */ - if (!NILP (map) - || EQ (pos_area, Qmode_line) - || EQ (pos_area, Qheader_line)) - local_map = map; - map = Fget_text_property (pos, Qkeymap, string); - if (!NILP (map) - || EQ (pos_area, Qmode_line) - || EQ (pos_area, Qheader_line)) - keymap = map; + local_map = Fget_text_property (pos, Qlocal_map, string); + keymap = Fget_text_property (pos, Qkeymap, string); } } -- cgit v1.2.1