Skip to content

Commit 0da2a86

Browse files
committed
tweak
1 parent 08810b3 commit 0da2a86

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

stdlib/REPL/src/History/resumablefiltering.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ function filterchunkrev!(out::Vector{HistEntry}, candidates::DenseVector{HistEnt
229229
end
230230
matchfail && continue
231231
pushfirst!(out, entry)
232-
if length(out) == maxresults
233-
break
234-
end
232+
length(out) == maxresults && break
235233
end
236234
end
237235
max(0, idx - 1)

stdlib/REPL/src/History/search.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
205203
end
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 ('\x03', '\x18') || 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

Comments
 (0)