1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Search history to back in the middle of histories

This commit is contained in:
aycabta 2019-12-02 03:05:10 +09:00
parent 4d7a6d04b2
commit e15b0313a7
2 changed files with 29 additions and 5 deletions

View file

@ -1145,10 +1145,12 @@ class Reline::LineEditor
alias_method :end_of_line, :ed_move_to_end
private def ed_search_prev_history(key)
if @is_multiline
@line_backup_in_history = whole_buffer
else
@line_backup_in_history = @line
unless @history_pointer
if @is_multiline
@line_backup_in_history = whole_buffer
else
@line_backup_in_history = @line
end
end
searcher = Fiber.new do
search_word = String.new(encoding: @encoding)
@ -1171,7 +1173,7 @@ class Reline::LineEditor
end
end
hit = nil
if @line_backup_in_history.include?(search_word)
if @line_backup_in_history&.include?(search_word)
@history_pointer = nil
hit = @line_backup_in_history
else

View file

@ -1430,6 +1430,28 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0)
end
def test_search_history_to_back_in_the_middle_of_histories
Reline::HISTORY.concat([
'1235', # old
'12aa',
'1234' # new
])
assert_line('')
assert_byte_pointer_size('')
assert_cursor(0)
assert_cursor_max(0)
input_keys("\C-p\C-p")
assert_line('12aa')
assert_byte_pointer_size('12aa')
assert_cursor(4)
assert_cursor_max(4)
input_keys("\C-r123")
assert_line('1235')
assert_byte_pointer_size('1235')
assert_cursor(4)
assert_cursor_max(4)
end
def test_em_set_mark_and_em_exchange_mark
input_keys('aaa bbb ccc ddd')
assert_byte_pointer_size('aaa bbb ccc ddd')