summaryrefslogtreecommitdiff
path: root/lisp/mouse.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2022-01-02 22:08:52 -0800
committerJuri Linkov <juri@linkov.net>2022-01-04 10:18:15 +0200
commit3eaf3aeec8a23dda8f9a170909bcc052c3d4ab78 (patch)
tree889ec53890605c716582325f06c645e301380b3d /lisp/mouse.el
parent9651be5b48691ced56230522e10c05a04455e4a3 (diff)
downloademacs-3eaf3aeec8a23dda8f9a170909bcc052c3d4ab78.tar.gz
Prevent further cases of duplicated separators in context menus
In some cases, context menu items are added before the overall prompt string. This could cause multiple consecutive separators to appear if they "surround" the prompt string. (Bug#52293) * lisp/mouse.el (context-menu-map): Improve the de-duplication logic to ignore non-menu-items when checking for consecutive separators. * test/lisp/mouse-tests.el (context-menu-map-remove-consecutive-separators) (context-menu-map-remove-separators-at-beginning-or-end): New tests.
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r--lisp/mouse.el34
1 files changed, 21 insertions, 13 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 0071420efc7..1a76b9a0b66 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -329,21 +329,29 @@ the function `context-menu-filter-function'."
;; Remove duplicate separators as well as ones at the beginning or
;; end of the menu.
- (let ((l menu) saw-first-item)
+ (let ((l menu) (last-saw-separator t))
(while (and (consp l)
(consp (cdr l)))
- ;; If the next item is a separator, remove it if 1) we haven't
- ;; seen any other items yet, or 2) it's followed by either
- ;; another separator or the end of the list.
- (if (and (equal (cdr-safe (cadr l)) menu-bar-separator)
- (or (not saw-first-item)
- (null (caddr l))
- (equal (cdr-safe (caddr l)) menu-bar-separator)))
- (setcdr l (cddr l))
- ;; The "first item" is any cons cell; this excludes the
- ;; `keymap' symbol and the menu name.
- (when (consp (cadr l)) (setq saw-first-item t))
- (setq l (cdr l)))))
+ (if (equal (cdr-safe (cadr l)) menu-bar-separator)
+ (progn
+ ;; The next item is a separator. Remove it if the last
+ ;; item we saw was a separator too.
+ (if last-saw-separator
+ (setcdr l (cddr l))
+ ;; If we didn't delete this separator, update the last
+ ;; separator we saw to this one.
+ (setq last-saw-separator l
+ l (cdr l))))
+ ;; If the next item is a cons cell, we found a non-separator
+ ;; item. Don't remove the next separator we see. We
+ ;; specifically check for cons cells to avoid treating the
+ ;; overall prompt string as a menu item.
+ (when (consp (cadr l))
+ (setq last-saw-separator nil))
+ (setq l (cdr l))))
+ ;; If the last item we saw was a separator, remove it.
+ (when (consp last-saw-separator)
+ (setcdr last-saw-separator (cddr last-saw-separator))))
(when (functionp context-menu-filter-function)
(setq menu (funcall context-menu-filter-function menu click)))