Fix keybinding alignment in `tmm-menubar'
* lisp/tmm.el (tmm--shorten-space-width): New function that reduces the space between the text menu entry and its keybinding to avoid a misalignement. (tmm-add-one-shortcut): Use it. (Bug#75500)
This commit is contained in:
parent
be786ab3bb
commit
ba5360f700
1 changed files with 19 additions and 3 deletions
22
lisp/tmm.el
22
lisp/tmm.el
|
@ -282,6 +282,17 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
|
|||
(let ((tmm-next-shortcut-digit ?0))
|
||||
(mapcar #'tmm-add-one-shortcut (reverse list))))
|
||||
|
||||
(defun tmm--shorten-space-width (str)
|
||||
"Shorten the width between the menu entry and the keybinding by 2 spaces."
|
||||
(let* ((start (next-single-property-change 0 'display str))
|
||||
(n (length str))
|
||||
(end (previous-single-property-change n 'display str))
|
||||
(curr-width (and start
|
||||
(plist-get (get-display-property start 'space str) :width))))
|
||||
(when curr-width
|
||||
(put-text-property start end 'display (cons 'space (list :width (- curr-width 2))) str))
|
||||
str))
|
||||
|
||||
(defsubst tmm-add-one-shortcut (elt)
|
||||
;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts
|
||||
(cond
|
||||
|
@ -327,9 +338,14 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
|
|||
(add-text-properties pos (1+ pos) '(face highlight) res)
|
||||
res)
|
||||
;; A fallback digit character: place it in front of the
|
||||
;; menu entry.
|
||||
(concat (propertize (char-to-string char) 'face 'highlight)
|
||||
" " str))
|
||||
;; menu entry. We need to shorten the spaces between
|
||||
;; the menu entry and the keybinding by two spaces
|
||||
;; because we added two characters at the front (one
|
||||
;; digit and one space) and this would cause a
|
||||
;; misalignement otherwise.
|
||||
(tmm--shorten-space-width
|
||||
(concat (propertize (char-to-string char) 'face 'highlight)
|
||||
" " str)))
|
||||
(make-string 2 ?\s))
|
||||
(concat (if char (concat (char-to-string char) tmm-mid-prompt)
|
||||
;; Keep them lined up in columns.
|
||||
|
|
Loading…
Add table
Reference in a new issue