mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Support incremental search again by C-r in incremental search
This commit is contained in:
parent
b3ea0980db
commit
103b04128f
2 changed files with 31 additions and 2 deletions
|
@ -1158,6 +1158,7 @@ class Reline::LineEditor
|
|||
last_hit = nil
|
||||
loop do
|
||||
key = Fiber.yield(search_word)
|
||||
search_again = false
|
||||
case key
|
||||
when "\C-h".ord, "\C-?".ord
|
||||
grapheme_clusters = search_word.grapheme_clusters
|
||||
|
@ -1165,6 +1166,8 @@ class Reline::LineEditor
|
|||
grapheme_clusters.pop
|
||||
search_word = grapheme_clusters.join
|
||||
end
|
||||
when "\C-r".ord
|
||||
search_again = true
|
||||
else
|
||||
multibyte_buf << key
|
||||
if multibyte_buf.dup.force_encoding(@encoding).valid_encoding?
|
||||
|
@ -1177,7 +1180,11 @@ class Reline::LineEditor
|
|||
@history_pointer = nil
|
||||
hit = @line_backup_in_history
|
||||
else
|
||||
if @history_pointer
|
||||
if search_again
|
||||
if @history_pointer
|
||||
history = Reline::HISTORY[0..(@history_pointer - 1)]
|
||||
end
|
||||
elsif @history_pointer
|
||||
history = Reline::HISTORY[0..@history_pointer]
|
||||
else
|
||||
history = Reline::HISTORY
|
||||
|
@ -1237,7 +1244,7 @@ class Reline::LineEditor
|
|||
@cursor = @byte_pointer = 0
|
||||
else
|
||||
chr = k.is_a?(String) ? k : k.chr(Encoding::ASCII_8BIT)
|
||||
if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == "\C-?".ord
|
||||
if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == "\C-?".ord or k == "\C-r".ord
|
||||
searcher.resume(k)
|
||||
else
|
||||
if @history_pointer
|
||||
|
|
|
@ -1452,6 +1452,28 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_twice
|
||||
Reline::HISTORY.concat([
|
||||
'1235', # old
|
||||
'12aa',
|
||||
'1234' # new
|
||||
])
|
||||
assert_line('')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
input_keys("\C-r123")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
input_keys("\C-r")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
end
|
||||
|
||||
def test_em_set_mark_and_em_exchange_mark
|
||||
input_keys('aaa bbb ccc ddd')
|
||||
assert_byte_pointer_size('aaa bbb ccc ddd')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue