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

    Improve lazy highlighting for quoted candidates (bug#77754)
---
 extensions/vertico-flat.el |  2 +-
 extensions/vertico-grid.el |  2 +-
 vertico.el                 | 19 +++++++++++++------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/extensions/vertico-flat.el b/extensions/vertico-flat.el
index a3c95a19ec..8242525644 100644
--- a/extensions/vertico-flat.el
+++ b/extensions/vertico-flat.el
@@ -114,7 +114,7 @@
     (while (and candidates (not (eq wrapped (car candidates)))
                 (> width 0) (> count 0))
       (let ((cand (pop candidates)) (prefix "") (suffix ""))
-        (setq cand (funcall vertico--hilit (substring cand)))
+        (setq cand (vertico--hilit cand))
         (pcase (and vertico-flat-annotate (vertico--affixate (list cand)))
           (`((,c ,p ,s)) (setq cand c prefix p suffix s)))
         (when (string-search "\n" cand)
diff --git a/extensions/vertico-grid.el b/extensions/vertico-grid.el
index b8e532c54a..9403a7261a 100644
--- a/extensions/vertico-grid.el
+++ b/extensions/vertico-grid.el
@@ -131,7 +131,7 @@ When scrolling beyond this limit, candidates may be 
truncated."
          (width (- (/ (vertico--window-width) vertico-grid--columns) sep))
          (cands (funcall (if (> vertico-grid-annotate 0) #'vertico--affixate 
#'identity)
                          (cl-loop repeat count for c in (nthcdr start 
vertico--candidates)
-                                  collect (funcall vertico--hilit (substring 
c)))))
+                                  collect (vertico--hilit c))))
          (cands (cl-loop
                  for cand in cands for index from 0 collect
                  (let (prefix suffix)
diff --git a/vertico.el b/vertico.el
index 8655774479..a69baba4bd 100644
--- a/vertico.el
+++ b/vertico.el
@@ -306,6 +306,12 @@ The value should lie between 0 and vertico-count/2."
                                           (test-completion content table 
pred)))
                                  -1 0))))))
 
+(defun vertico--hilit (cand)
+  "Highlight CAND string with lazy highlighting."
+  ;; bug#77754: Highlight unquoted string.
+  (funcall vertico--hilit (substring (or (get-text-property
+                                          0 'completion--unquoted cand) 
cand))))
+
 (defun vertico--cycle (list n)
   "Rotate LIST to position N."
   (nconc (copy-sequence (nthcdr n list)) (seq-take list n)))
@@ -419,11 +425,12 @@ The value should lie between 0 and vertico-count/2."
 
 (defun vertico--format-group-title (title cand)
   "Format group TITLE given the current CAND."
+  ;; Copy candidate highlighting if title is a prefix of the candidate.
   (when (string-prefix-p title cand)
-    ;; Highlight title if title is a prefix of the candidate
-    (setq cand (propertize cand 'face 'vertico-group-title)
-          title (substring (funcall vertico--hilit cand) 0 (length title)))
+    (setq title (substring cand 0 (length title)))
     (vertico--remove-face 0 (length title) 'completions-first-difference 
title))
+  (setq title (substring title))
+  (add-face-text-property 0 (length title) 'vertico-group-title t title)
   (format (concat vertico-group-format "\n") title))
 
 (defun vertico--format-count ()
@@ -474,7 +481,7 @@ The value should lie between 0 and vertico-count/2."
 
 (defun vertico--candidate (&optional hl)
   "Return current candidate string with optional highlighting if HL is 
non-nil."
-  (let ((content (substring (or (car-safe vertico--input) 
(minibuffer-contents-no-properties)))))
+  (let ((content (or (car-safe vertico--input) 
(minibuffer-contents-no-properties))))
     (cond
      ((>= vertico--index 0)
       (let ((cand (substring (nth vertico--index vertico--candidates))))
@@ -482,7 +489,7 @@ The value should lie between 0 and vertico-count/2."
         ;; `completion--twq-all' hack.  This should better be fixed in Emacs
         ;; itself, the corresponding code is already marked as fixme.
         (vertico--remove-face 0 (length cand) 'completions-common-part cand)
-        (concat vertico--base (if hl (funcall vertico--hilit cand) cand))))
+        (concat vertico--base (if hl (vertico--hilit cand) cand))))
      ((and (equal content "") (or (car-safe minibuffer-default) 
minibuffer-default)))
      (t content))))
 
@@ -513,7 +520,7 @@ The value should lie between 0 and vertico-count/2."
            (candidates
             (vertico--affixate
              (cl-loop repeat vertico-count for c in (nthcdr index 
vertico--candidates)
-                      collect (funcall vertico--hilit (substring c))))))
+                      collect (vertico--hilit c)))))
       (pcase-dolist ((and cand `(,str . ,_)) candidates)
         (when-let ((new-title (and group-fun (funcall group-fun str nil))))
           (unless (equal title new-title)

Reply via email to