Prevent which-key faces from over-extending during formatting
authorPhilip Kaludercic <philipk@posteo.net>
Tue, 18 Jun 2024 08:40:01 +0000 (10:40 +0200)
committerPhilip Kaludercic <philipk@posteo.net>
Tue, 18 Jun 2024 09:31:04 +0000 (11:31 +0200)
* lisp/which-key.el (which-key--pad-column): Instead of
injecting the description using a left-aligned format-string (%-[n]s),
we manually add the necessary padding so that the text
properties don't extend beyond the description.  This allows us
to use a face with a background without it extending until the
end of a column.

See also 63a6fb2a7a02ca88835c3fd473894d3b7d39ff15 for a similar
issue with Quick Help.

lisp/which-key.el

index a2355527dd31a54d9043930aee5fd72c83069169..a4720040f7ab85717401e6b42db77dea99e32068 100644 (file)
@@ -2005,10 +2005,12 @@ that width."
                                col-keys 2
                                which-key-min-column-description-width)))
          (col-width      (+ col-key-width col-sep-width col-desc-width))
-         (col-format     (concat "%" (int-to-string col-key-width)
-                                 "s%s%-" (int-to-string col-desc-width) "s")))
+         (col-format     (concat "%" (int-to-string col-key-width) "s%s%s")))
     (cons col-width
-          (mapcar (lambda (k) (apply #'format col-format k))
+          (mapcar (pcase-lambda (`(,key ,sep ,desc ,_doc))
+                    (concat
+                     (format col-format key sep desc)
+                     (make-string (- col-desc-width (length desc)) ?\s)))
                   col-keys))))
 
 (defun which-key--partition-list (n list)