зеркало из https://github.com/github/ruby.git
Support change search direction
This commit is contained in:
Родитель
a14a0244b4
Коммит
618d091151
|
@ -1196,6 +1196,7 @@ class Reline::LineEditor
|
||||||
loop do
|
loop do
|
||||||
key = Fiber.yield(search_word)
|
key = Fiber.yield(search_word)
|
||||||
search_again = false
|
search_again = false
|
||||||
|
change_direction = false
|
||||||
case key
|
case key
|
||||||
when -1 # determined
|
when -1 # determined
|
||||||
Reline.last_incremental_search = search_word
|
Reline.last_incremental_search = search_word
|
||||||
|
@ -1207,7 +1208,11 @@ class Reline::LineEditor
|
||||||
search_word = grapheme_clusters.join
|
search_word = grapheme_clusters.join
|
||||||
end
|
end
|
||||||
when "\C-r".ord, "\C-s".ord
|
when "\C-r".ord, "\C-s".ord
|
||||||
search_again = true if prev_search_key == key
|
if prev_search_key == key
|
||||||
|
search_again = true
|
||||||
|
else
|
||||||
|
change_direction = true
|
||||||
|
end
|
||||||
prev_search_key = key
|
prev_search_key = key
|
||||||
else
|
else
|
||||||
multibyte_buf << key
|
multibyte_buf << key
|
||||||
|
@ -1229,10 +1234,19 @@ class Reline::LineEditor
|
||||||
case prev_search_key
|
case prev_search_key
|
||||||
when "\C-r".ord
|
when "\C-r".ord
|
||||||
history_pointer_base = 0
|
history_pointer_base = 0
|
||||||
history = Reline::HISTORY[0..(@history_pointer - 1)]
|
if change_direction
|
||||||
|
history = Reline::HISTORY[0..@history_pointer]
|
||||||
|
else
|
||||||
|
history = Reline::HISTORY[0..(@history_pointer - 1)]
|
||||||
|
end
|
||||||
when "\C-s".ord
|
when "\C-s".ord
|
||||||
history_pointer_base = @history_pointer + 1
|
if change_direction
|
||||||
history = Reline::HISTORY[(@history_pointer + 1)..-1]
|
history_pointer_base = @history_pointer
|
||||||
|
history = Reline::HISTORY[(@history_pointer)..-1]
|
||||||
|
else
|
||||||
|
history_pointer_base = @history_pointer + 1
|
||||||
|
history = Reline::HISTORY[(@history_pointer + 1)..-1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
history_pointer_base = 0
|
history_pointer_base = 0
|
||||||
|
@ -1242,10 +1256,19 @@ class Reline::LineEditor
|
||||||
case prev_search_key
|
case prev_search_key
|
||||||
when "\C-r".ord
|
when "\C-r".ord
|
||||||
history_pointer_base = 0
|
history_pointer_base = 0
|
||||||
history = Reline::HISTORY[0..@history_pointer]
|
if change_direction
|
||||||
|
history = Reline::HISTORY[0..@history_pointer]
|
||||||
|
else
|
||||||
|
history = Reline::HISTORY[0..@history_pointer]
|
||||||
|
end
|
||||||
when "\C-s".ord
|
when "\C-s".ord
|
||||||
history_pointer_base = @history_pointer
|
if change_direction
|
||||||
history = Reline::HISTORY[@history_pointer..-1]
|
history_pointer_base = @history_pointer
|
||||||
|
history = Reline::HISTORY[(@history_pointer - 1)..-1]
|
||||||
|
else
|
||||||
|
history_pointer_base = @history_pointer
|
||||||
|
history = Reline::HISTORY[@history_pointer..-1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
history_pointer_base = 0
|
history_pointer_base = 0
|
||||||
|
|
|
@ -1620,6 +1620,70 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
||||||
assert_cursor_max(0)
|
assert_cursor_max(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_search_history_front_and_back
|
||||||
|
Reline::HISTORY.concat([
|
||||||
|
'1235', # old
|
||||||
|
'12aa',
|
||||||
|
'1234' # new
|
||||||
|
])
|
||||||
|
assert_line('')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-s12")
|
||||||
|
assert_line('1235')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0) # doesn't determine yet
|
||||||
|
input_keys("\C-s")
|
||||||
|
assert_line('12aa')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-r")
|
||||||
|
assert_line('12aa')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-r")
|
||||||
|
assert_line('1235')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_search_history_back_and_front
|
||||||
|
Reline::HISTORY.concat([
|
||||||
|
'1235', # old
|
||||||
|
'12aa',
|
||||||
|
'1234' # new
|
||||||
|
])
|
||||||
|
assert_line('')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-r12")
|
||||||
|
assert_line('1234')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0) # doesn't determine yet
|
||||||
|
input_keys("\C-r")
|
||||||
|
assert_line('12aa')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-s")
|
||||||
|
assert_line('12aa')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
input_keys("\C-s")
|
||||||
|
assert_line('1234')
|
||||||
|
assert_byte_pointer_size('')
|
||||||
|
assert_cursor(0)
|
||||||
|
assert_cursor_max(0)
|
||||||
|
end
|
||||||
|
|
||||||
def test_search_history_to_back_in_the_middle_of_histories
|
def test_search_history_to_back_in_the_middle_of_histories
|
||||||
Reline::HISTORY.concat([
|
Reline::HISTORY.concat([
|
||||||
'1235', # old
|
'1235', # old
|
||||||
|
|
Загрузка…
Ссылка в новой задаче