diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2022-02-25 15:57:50 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2022-02-25 15:57:50 +0100 |
| commit | 58459b614372a39e2cf80f4ffd959a5d2272fa8a (patch) | |
| tree | cc5a92bff6c5832865d185ef639d5248bad8ad88 | |
| parent | 0a16d1525734d1ab6893076c8329bb44fd78c871 (diff) | |
Ensure that annotations don't fall off the popup (Fix #135)
| -rw-r--r-- | corfu.el | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -717,22 +717,27 @@ there hasn't been any input, then quit." (let* ((cw (cl-loop for x in cands maximize (string-width (car x)))) (pw (cl-loop for x in cands maximize (string-width (cadr x)))) (sw (cl-loop for x in cands maximize (string-width (caddr x)))) - (width (+ pw cw sw))) + (width (+ pw cw sw)) + ;; -4 because of margins and some additional safety + (max-width (min corfu-max-width (- (frame-width) 4)))) + (when (> width max-width) + (setq sw (max 0 (- max-width pw cw)) + width (+ pw cw sw))) (when (< width corfu-min-width) (setq cw (+ cw (- corfu-min-width width)) width corfu-min-width)) - ;; -4 because of margins and some additional safety - (setq width (min width corfu-max-width (- (frame-width) 4))) + (setq width (min width max-width)) (list pw width (cl-loop for (cand prefix suffix) in cands collect (truncate-string-to-width (concat prefix - (make-string (- pw (string-width prefix)) ?\s) + (make-string (max 0 (- pw (string-width prefix))) ?\s) cand (when (/= sw 0) - (make-string (+ (- cw (string-width cand)) - (- sw (string-width suffix))) - ?\s)) + (make-string + (+ (max 0 (- cw (string-width cand))) + (max 0 (- sw (string-width suffix)))) + ?\s)) suffix) width))))) |
