Skip to content

Commit

Permalink
fix repl rsearch with one-char query
Browse files Browse the repository at this point in the history
The backward i-search needs to set the "start" parameter of rsearch
to the end (minus 1) of the current search window.
This fixes e.g.:
* searching backwards only one character remains stuck on the same match
* searching backwards 'aaa' skips one of the matches in 'aaaa'
  • Loading branch information
rfourquet committed Dec 14, 2014
1 parent ebdaed7 commit 55f45e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@ function history_search(hist::REPLHistoryProvider, query_buffer::IOBuffer, respo
return true
end

searchfunc,delta = backwards ? (rsearch,0) : (search,1)
searchfunc, searchstart = backwards ? (rsearch, b-1) : (search, a+1)

# Start searching
# First the current response buffer
if 1 <= a+delta <= length(response_str)
match = searchfunc(response_str, searchdata, a+delta)
if 1 <= searchstart <= length(response_str)
match = searchfunc(response_str, searchdata, searchstart)
if match != 0:-1
seek(response_buffer, first(match)-1)
return true
Expand Down
11 changes: 11 additions & 0 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ begin
@test LineEdit.mode(s) == shell_mode
@test buffercontents(LineEdit.buffer(s)) == "ll"

# Test that searching backwards with a one-letter query doesn't
# return indefinitely the same match.
LineEdit.enter_search(s, histp, true)
write(ss.query_buffer, "l")
LineEdit.update_display_buffer(ss, ss)
LineEdit.history_next_result(s, ss)
LineEdit.update_display_buffer(ss, ss)
LineEdit.accept_result(s, histp)
@test LineEdit.mode(s) == repl_mode
@test buffercontents(LineEdit.buffer(s)) == "shell"

# Issue #7551
# Enter search mode and try accepting an empty result
REPL.history_reset_state(hp)
Expand Down

0 comments on commit 55f45e0

Please sign in to comment.