Skip to content

Commit

Permalink
Fix horizontal off-by-one error
Browse files Browse the repository at this point in the history
Delay increasing width used by columns until we know that we have to
do so because we have determined that there is enough room to add an
additional column and a space between the last two columns.

If we don't do that, then we can easily get an off-by-one error.  If
docstrings are shown and the window is narrow, then it is likely that
we end up using the maximal width.  If we then add one to the actual
width and later compare that again with the maximal width, then that
is too width.
  • Loading branch information
tarsius committed Aug 4, 2022
1 parent 254d6fd commit 5fe2d33
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions which-key.el
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ that width."
(which-key--max-len
col-keys 2
which-key-min-column-description-width)))
(col-width (+ 1 col-key-width col-sep-width col-desc-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")))
(cons col-width
Expand Down Expand Up @@ -1915,10 +1915,10 @@ as well as metadata."
(while (and cols-w-widths
(or (null which-key-max-display-columns)
(< n-columns which-key-max-display-columns))
(<= (+ (caar cols-w-widths) page-width) avl-width))
(<= (+ page-width 1 (caar cols-w-widths)) avl-width))
(setq col (pop cols-w-widths))
(push (cdr col) page-cols)
(cl-incf page-width (car col))
(cl-incf page-width (1+ (car col)))
(cl-incf n-keys (length (cdr col)))
(cl-incf n-columns))
(push (which-key--join-columns page-cols) pages)
Expand Down

0 comments on commit 5fe2d33

Please sign in to comment.