Skip to content

Commit 25b010f

Browse files
committed
Skip consecutive identical history records in UI
While the initial history itself doesn't contain consecutive identical entries, once you filter for a certain condition it's easy to end up with spans of identical entries, which isn't at all helpful. Let's just keep the most recent one.
1 parent 120a542 commit 25b010f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

stdlib/REPL/src/History/resumablefiltering.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,25 @@ Incrementally filter `candidates[1:idx]` in reverse order.
259259
260260
Pushes matches onto `out` until either `maxtime` is exceeded or `maxresults`
261261
collected, then returns the new resume index.
262+
263+
When there are consecutive entries with identical content and state, all but the
264+
most recent are skipped.
262265
"""
263266
function filterchunkrev!(out::Vector{HistEntry}, candidates::DenseVector{HistEntry},
264267
spec::FilterSpec, idx::Int = length(candidates);
265268
maxtime::Float64 = Inf, maxresults::Int = length(candidates))
269+
lightentry(e) = (e.mode, e.content) # for similarity checking
266270
batchsize = clamp(length(candidates) ÷ 512, 10, 1000)
271+
prevaccepted = if isempty(out)
272+
HistEntry(:none, DateTime(0), "", 0)
273+
else
274+
first(out)
275+
end |> lightentry
267276
for batch in Iterators.partition(idx:-1:1, batchsize)
268277
time() > maxtime && break
269278
for outer idx in batch
270279
entry = candidates[idx]
280+
lightentry(entry) == prevaccepted && continue
271281
if !isempty(spec.modes)
272282
entry.mode spec.modes || continue
273283
end
@@ -294,6 +304,7 @@ function filterchunkrev!(out::Vector{HistEntry}, candidates::DenseVector{HistEnt
294304
end
295305
matchfail && continue
296306
pushfirst!(out, entry)
307+
prevaccepted = lightentry(entry)
297308
length(out) == maxresults && break
298309
end
299310
end

0 commit comments

Comments
 (0)