abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

Dynamic-Sources Highlight Doesn't Update #1877

Open dustinlacewell opened 5 years ago

dustinlacewell commented 5 years ago

With the following snippet in play, the match highlight face is not updating properly in this dictionary I'm working on:

(defun sutysisku-ivy-candidates (str)
  (when (and (not (equal str nil)) (not (equal str "")))
    (let ((exact)
          (gloss-exact)
          (word-prefix)
          (word-substring)
          (gloss-prefix)
          (gloss-substring)
          (definition-substring))
      (cl-loop for item in sutysisku--data
               for display = (car item)
               for record = (cdr item)
               for word = (a-get record :word)
               for gloss = (a-get record :gloss)
               for definition = (a-get record :definition)
               do (cond
                   ((s-equals? str word)
                    (setf exact (append (list display) exact)))

                   ((s-equals? str gloss)
                    (setf gloss-exact (append (list display) exact)))

                   ((s-prefix? str word)
                    (setf word-prefix (append (list display) word-prefix)))

                   ((s-contains? str word)
                    (setf word-substring (append (list display) word-substring)))

                   ((s-prefix? str gloss)
                    (setf gloss-prefix (append (list display) gloss-prefix)))

                   ((s-contains? str gloss)
                    (setf gloss-substring (append (list display) gloss-substring)))

                   ((s-contains? str definition)
                    (setf definition-substring (append (list display) definition-substring)))))
      (append
             exact gloss-exact
             word-prefix word-substring
             gloss-prefix gloss-substring
             definition-substring))))

(defun sutysisku-search-ivy ()
  (interactive)
  (if (> (length sutysisku--data) 0)
      (ivy-read
       "vlasisku: " 'sutysisku-ivy-candidates
       :dynamic-collection t)
    (sutysisku-fetch 'sutysisku-search)))

The behavior can be seen in the following video where the highlight is stuck on "apple":

https://youtu.be/1svrfPF0sus

CeleritasCelery commented 5 years ago

Why are you using dyanmic-collection in the first place? your code doesn't seem to call any external process.

dustinlacewell commented 5 years ago

If you look at the first function, it is dynamically building a list of results by composing several smaller lists together, in effect grouping and prioritizing some results over others based on the search. It isn't just filtering a known set of alphabetically sorted entries by the search input.

CeleritasCelery commented 5 years ago

How you want to handle this is to pass all the candidates at once, then define a :matcher and :sort functions that do any special handling. You don’t need a dynamic collection.

abo-abo commented 5 years ago

@dustinlacewell Please post the extra config (packages to install, etc) in order for me to reproduce this.