branch: externals/vertico
commit 180f54d933db295a2d5eac1c73eac23fdfa2e8aa
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    Ensure that vertico-quick and vertico-flat are compatible
---
 extensions/vertico-quick.el | 46 +++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/extensions/vertico-quick.el b/extensions/vertico-quick.el
index 69dce8b..e75e1fe 100644
--- a/extensions/vertico-quick.el
+++ b/extensions/vertico-quick.el
@@ -64,28 +64,30 @@
   (let* ((fst (length vertico-quick1))
          (snd (length vertico-quick2))
          (len (+ fst snd))
-         (idx (- index start)))
-    (funcall orig cand
-             (concat
-              (if (>= idx fst)
-                  (let ((first (elt vertico-quick2 (mod (/ (- idx fst) len) 
snd)))
-                        (second (elt (concat vertico-quick1 vertico-quick2) 
(mod (- idx fst) len))))
-                    (push (cons first t) vertico-quick--list)
-                    (push (cons (+ first (lsh second 16)) index) 
vertico-quick--list)
-                    (cond
-                     ((eq first vertico-quick--first)
-                      (concat " " (propertize (char-to-string second) 'face 
'vertico-quick1)))
-                     (vertico-quick--first "  ")
-                     (t
-                      (concat (propertize (char-to-string first) 'face 
'vertico-quick1)
-                              (propertize (char-to-string second) 'face 
'vertico-quick2)))))
-                (let ((first (elt vertico-quick1 (mod idx fst))))
-                  (push (cons first index) vertico-quick--list)
-                  (if vertico-quick--first
-                      "  "
-                    (concat (propertize (char-to-string first) 'face 
'vertico-quick1) " "))))
-              (make-string (max 1 (- (length prefix) 2)) ?\s))
-             suffix index start)))
+         (idx (- index start))
+         (keys (if (>= idx fst)
+                   (let ((first (elt vertico-quick2 (mod (/ (- idx fst) len) 
snd)))
+                         (second (elt (concat vertico-quick1 vertico-quick2) 
(mod (- idx fst) len))))
+                     (push (cons first t) vertico-quick--list)
+                     (push (cons (+ first (lsh second 16)) index) 
vertico-quick--list)
+                     (cond
+                      ((eq first vertico-quick--first)
+                       (concat " " (propertize (char-to-string second) 'face 
'vertico-quick1)))
+                      (vertico-quick--first "  ")
+                      (t
+                       (concat (propertize (char-to-string first) 'face 
'vertico-quick1)
+                               (propertize (char-to-string second) 'face 
'vertico-quick2)))))
+                 (let ((first (elt vertico-quick1 (mod idx fst))))
+                   (push (cons first index) vertico-quick--list)
+                   (if vertico-quick--first
+                       "  "
+                     (concat (propertize (char-to-string first) 'face 
'vertico-quick1) " "))))))
+    (if (bound-and-true-p vertico-flat-mode)
+        (setq keys (replace-regexp-in-string " " "" keys)
+              cand (string-trim cand)
+              cand (substring cand (min (length cand) (length keys))))
+      (setq keys (concat keys (make-string (max 1 (- (length prefix) 2)) 
?\s))))
+    (funcall orig cand keys suffix index start)))
 
 ;;;###autoload
 (defun vertico-quick-jump ()

Reply via email to