Skip to content

Commit

Permalink
In ed_search_next_history, make the cursor come to the end of the lin…
Browse files Browse the repository at this point in the history
…e when there is no search substr
  • Loading branch information
QWYNG committed May 30, 2024
1 parent baf24bd commit ef1ef00
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'reline/config'
require 'reline/key_actor'
require 'reline/key_stroke'
require 'reline/line_editor'
require_relative 'reline/line_editor'
require 'reline/history'
require 'reline/terminfo'
require 'reline/face'
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ def finish
h_pointer, line_index = search_history(substr, history_range)
return if h_pointer.nil? and not substr.empty?

move_history(h_pointer, line: line_index || :start, cursor: @byte_pointer)
move_history(h_pointer, line: line_index || :start, cursor: substr.empty? ? :end : @byte_pointer)
arg -= 1
ed_search_next_history(key, arg: arg) if arg > 0
end
Expand Down
12 changes: 7 additions & 5 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1293,15 +1293,17 @@ def test_ed_search_next_history_with_empty
])
# The ed_search_prev_history and ed_search_next_history doesn't have default binding
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
assert_line_around_cursor('', '12345')
assert_line_around_cursor('12345', '')
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
assert_line_around_cursor('', '12aaa')
assert_line_around_cursor('12345', '')
3.times { input_key_by_symbol(:ed_prev_char) }
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
assert_line_around_cursor('', '12356')
assert_line_around_cursor('12', 'aaa')
@line_editor.__send__(:ed_search_next_history, "\C-n".ord)
assert_line_around_cursor('', '12aaa')
assert_line_around_cursor('12', '345')
@line_editor.__send__(:ed_search_next_history, "\C-n".ord)
assert_line_around_cursor('', '12345')
assert_line_around_cursor('12', '345')
2.times { input_key_by_symbol(:ed_prev_char) }
@line_editor.__send__(:ed_search_next_history, "\C-n".ord)
assert_line_around_cursor('', '')
end
Expand Down

0 comments on commit ef1ef00

Please sign in to comment.