@@ -134,8 +134,6 @@ function run_display!((; term, pstate), events::Channel{Symbol}, hist::Vector{Hi
134134 for act in prevstate. selection. active
135135 push! (state. selection. gathered, prevstate. candidates[act])
136136 end
137- filter! (g -> isempty (searchsorted (state. candidates, g, by = e -> e. index)),
138- state. selection. gathered)
139137 sort! (state. selection. gathered, by = e -> e. index)
140138 state = SelectorState (
141139 state. area, state. query, state. filter, state. candidates,
@@ -157,9 +155,9 @@ function run_display!((; term, pstate), events::Channel{Symbol}, hist::Vector{Hi
157155 end
158156 # Start filtering candidates
159157 filter_idx = filterchunkrev! (
160- state. candidates , cands_current, state . filter ;
158+ state, cands_current;
161159 maxtime = time () + 0.01 ,
162- maxresults = 2 * outsize[1 ] ÷ 3 )
160+ maxresults = outsize[1 ])
163161 if filter_idx == 0
164162 cands_cachestate = addcache! (
165163 cands_cache, cands_cachestate, cands_cond => state. candidates)
@@ -187,15 +185,15 @@ function run_display!((; term, pstate), events::Channel{Symbol}, hist::Vector{Hi
187185 state. area, state. query, state. filter, cands_temp,
188186 state. scroll, state. selection, state. hover)
189187 filter_idx = filterchunkrev! (
190- state. candidates , cands_current, state . filter , filter_idx;
188+ state, cands_current, filter_idx;
191189 maxtime = time () + 0.01 )
192190 if filter_idx == 0
193191 cands_cachestate = addcache! (
194192 cands_cache, cands_cachestate, cands_cond => state. candidates)
195193 end
196194 # If there are now new candidates in the view, update
197195 length (state. candidates) != length (prevstate. candidates) &&
198- length (state . candidates) - state. hover < outsize[1 ] &&
196+ length (prevstate . candidates) - state. hover < outsize[1 ] &&
199197 redisplay_all (out, prevstate, state, pstate; buf)
200198 elseif isnothing (event)
201199 yield ()
@@ -204,6 +202,24 @@ function run_display!((; term, pstate), events::Channel{Symbol}, hist::Vector{Hi
204202 end
205203end
206204
205+ function filterchunkrev! (state:: SelectorState , candidates:: DenseVector{HistEntry} , idx:: Int = length (candidates);
206+ maxtime:: Float64 = Inf , maxresults:: Int = length (candidates))
207+ oldlen = length (state. candidates)
208+ idx = filterchunkrev! (state. candidates, candidates, state. filter, idx;
209+ maxtime = maxtime, maxresults = maxresults)
210+ newlen = length (state. candidates)
211+ newcands = view (state. candidates, (oldlen + 1 ): newlen)
212+ gfound = Int[]
213+ for (i, g) in enumerate (state. selection. gathered)
214+ cind = searchsorted (newcands, g, by = e -> e. index)
215+ isempty (cind) && continue
216+ push! (state. selection. active, oldlen + first (cind))
217+ push! (gfound, i)
218+ end
219+ isempty (gfound) || deleteat! (state. selection. gathered, gfound)
220+ idx
221+ end
222+
207223"""
208224 movehover(state::SelectorState, backwards::Bool, page::Bool)
209225
@@ -329,7 +345,7 @@ function savetext(term::Base.Terminals.TTYTerminal, content_::String)
329345 if ichar ∈ (' \x 03' , ' \x 18' ) || char == ichar == ' \e '
330346 println (out, S "\e [1G\e [2K{light,grey:{bold:history>} {red:×} History selection aborted}\n " )
331347 return
332- elseif char == ' \r '
348+ elseif ichar == ' \r '
333349 break
334350 end
335351 char = ichar
0 commit comments