diff options
| author | Spencer Baugh | 2025-09-26 18:13:30 -0400 |
|---|---|---|
| committer | Eli Zaretskii | 2025-10-18 12:48:41 +0300 |
| commit | bea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c (patch) | |
| tree | 3d3ae3d45ee090ecdab3167d72f0b7c9f82156a2 /test/src | |
| parent | 59da5020da703aae784ec8afeaa32348c6b6bfd5 (diff) | |
| download | emacs-bea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c.tar.gz emacs-bea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c.zip | |
Respect keymaps in buffer text for clicks on displayed strings
When clicking on a string displayed by a display property, also
look at the text properties of the underlying buffer text for
keymaps, not just the displayed string. The displayed string
takes precedence over the buffer text, but it doesn't replace
it.
Also, we should use the buffer's local map even for clicks on
the mode line. (Otherwise, what's the point of the <mode-line>
event?)
* src/keymap.c (Fcurrent_active_maps): Consider displayed
string, then buffer text, then fall back to local
map. (Bug#79505)
* test/src/keymap-tests.el
(keymap-test-keymaps-for-non-buffer-positions): Add more tests.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/keymap-tests.el | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el index 950c741a6dd..0d203f6fcb0 100644 --- a/test/src/keymap-tests.el +++ b/test/src/keymap-tests.el | |||
| @@ -509,25 +509,36 @@ g .. h foo | |||
| 509 | ;; From the parent this time/ | 509 | ;; From the parent this time/ |
| 510 | (should (equal (keymap-lookup map "u") #'undo)))) | 510 | (should (equal (keymap-lookup map "u") #'undo)))) |
| 511 | 511 | ||
| 512 | (defun keymap-test--get-maps (posn) | ||
| 513 | (let ((maps (current-active-maps nil posn))) | ||
| 514 | ;; The local map should always be present. | ||
| 515 | (should (memq (current-local-map) maps)) | ||
| 516 | maps)) | ||
| 517 | |||
| 512 | (defun keymap-test--maps-for-posn (area string) | 518 | (defun keymap-test--maps-for-posn (area string) |
| 513 | (current-active-maps | 519 | (keymap-test--get-maps |
| 514 | nil | ||
| 515 | ;; FIXME: This test would be better if this was a real position | 520 | ;; FIXME: This test would be better if this was a real position |
| 516 | ;; created by a real click. | 521 | ;; created by a real click. |
| 517 | `(,(selected-window) ,area (1 . 1) 0 (,string . 0) nil (1 . 1) nil (1 . 1) (1 . 1)))) | 522 | (let (;; If AREA is passed, the click isn't in the buffer; otherwise |
| 523 | ;; it's at position 1. | ||
| 524 | (pos (if area nil 1))) | ||
| 525 | `(,(selected-window) ,area (1 . 1) 0 (,string . 0) | ||
| 526 | ,pos (1 . 1) nil (1 . 1) (1 . 1))))) | ||
| 518 | 527 | ||
| 519 | (ert-deftest keymap-test-keymaps-for-non-buffer-positions () | 528 | (ert-deftest keymap-test-keymaps-for-non-buffer-positions () |
| 520 | "`current-active-maps' with non-buffer positions. (bug#76620)" | 529 | "`current-active-maps' with non-buffer positions. (bug#76620)" |
| 521 | (with-temp-buffer | 530 | (with-temp-buffer |
| 522 | (pop-to-buffer (current-buffer)) | 531 | (pop-to-buffer (current-buffer)) |
| 523 | (let ((keymap (make-sparse-keymap "keymap-at-point"))) | 532 | (let ((keymap (make-sparse-keymap "keymap-at-point"))) |
| 533 | (use-local-map (make-sparse-keymap "buffer-local-map")) | ||
| 524 | (insert (propertize "string" 'keymap keymap)) | 534 | (insert (propertize "string" 'keymap keymap)) |
| 525 | (goto-char (point-min)) | 535 | (goto-char (point-min)) |
| 526 | (should (memq keymap (current-active-maps))) | 536 | (should (memq keymap (keymap-test--get-maps nil))) |
| 527 | (should-not (memq keymap (keymap-test--maps-for-posn 'mode-line nil))) | 537 | (should-not (memq keymap (keymap-test--maps-for-posn 'mode-line nil))) |
| 528 | (should-not (memq keymap (keymap-test--maps-for-posn 'mode-line "s"))) | 538 | (should-not (memq keymap (keymap-test--maps-for-posn 'mode-line "s"))) |
| 529 | (should-not (memq keymap (keymap-test--maps-for-posn nil "s"))) | 539 | (should (memq keymap (keymap-test--maps-for-posn nil "s"))) |
| 530 | (should (memq keymap (keymap-test--maps-for-posn nil nil))) | 540 | (should (memq keymap (keymap-test--maps-for-posn nil nil))) |
| 541 | (should (memq keymap (keymap-test--get-maps "a"))) | ||
| 531 | (let* ((mode-line-keymap (make-sparse-keymap "keymap-in-mode-line")) | 542 | (let* ((mode-line-keymap (make-sparse-keymap "keymap-in-mode-line")) |
| 532 | (s (propertize "string" 'keymap mode-line-keymap))) | 543 | (s (propertize "string" 'keymap mode-line-keymap))) |
| 533 | ;; Respect `keymap' in the string clicked on. | 544 | ;; Respect `keymap' in the string clicked on. |