From 58459b614372a39e2cf80f4ffd959a5d2272fa8a Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 25 Feb 2022 15:57:50 +0100 Subject: Ensure that annotations don't fall off the popup (Fix #135) --- corfu.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/corfu.el b/corfu.el index 0b6e5ac..e92bce6 100644 --- a/corfu.el +++ b/corfu.el @@ -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))))) -- cgit v1.0