8000 Handle ed_search_{prev,next}_history in multiline correctly · ruby/reline@a3df434 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3df434

Browse files
committed
Handle ed_search_{prev,next}_history in multiline correctly
The current line was being handled incorrectly when displaying the hit history, so it has been fixed to be correct.
1 parent 22c6db7 commit a3df434

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

lib/reline/line_editor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ def finish
17321732
@buffer_of_lines = Reline::HISTORY[@history_pointer].split("\n")
17331733
@buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty?
17341734
@line_index = line_no
1735-
@line = @buffer_of_lines.last
1735+
@line = @buffer_of_lines[@line_index]
17361736
@rerender_all = true
17371737
else
17381738
@line = Reline::HISTORY[@history_pointer]
@@ -1780,7 +1780,7 @@ def finish
17801780
@line_index = line_no
17811781
end
17821782
@buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty?
1783-
@line = @buffer_of_lines.last
1783+
@line = @buffer_of_lines[@line_index]
17841784
@rerender_all = true
17851785
else
17861786
if @history_pointer.nil? and substr.empty?

test/reline/helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ def assert_cursor(expected)
9696
def assert_cursor_max(expected)
9797
assert_equal(expected, @line_editor.instance_variable_get(:@cursor_max))
9898
end
99+
100+
def assert_line_index(expected)
101+
assert_equal(expected, @line_editor.instance_variable_get(:@line_index))
102+
end
103+
104+
def assert_whole_lines(expected)
105+
previous_line_index = @line_editor.instance_variable_get(:@previous_line_index)
106+
if previous_line_index
107+
lines = @line_editor.whole_lines(index: previous_line_index)
108+
else
109+
lines = @line_editor.whole_lines
110+
end
111+
assert_equal(expected, lines)
112+
end
99113
end

test/reline/test_key_actor_emacs.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,53 @@ def test_em_kill_region_with_kill_ring
22332233
assert_line('def hoge')
22342234
end
22352235

2236+
def test_ed_search_prev_next_history_in_multibyte
2237+
Reline::HISTORY.concat([
2238+
"def hoge\n 67890\n 12345\nend", # old
2239+
"def aiu\n 0xDEADBEEF\nend",
2240+
"def foo\n 12345\nend" # new
2241+
])
2242+
@line_editor.multiline_on
2243+
input_keys(' 123')
2244+
# The ed_search_prev_history doesn't have default binding
2245+
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
2246+
assert_whole_lines(['def foo', ' 12345', 'end'])
2247+
assert_line_index(1)
2248+
assert_whole_lines(['def foo', ' 12345', 'end'])
2249+
assert_byte_pointer_size(' 123')
2250+
asser 8000 t_cursor(5)
2251+
assert_cursor_max(7)
2252+
assert_line(' 12345')
2253+
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
2254+
assert_line_index(2)
2255+
assert_whole_lines(['def hoge', ' 67890', ' 12345', 'end'])
2256+
assert_byte_pointer_size(' 123')
2257+
assert_cursor(5)
2258+
assert_cursor_max(7)
2259+
assert_line(' 12345')
2260+
@line_editor.__send__(:ed_search_prev_history, "\C-p".ord)
2261+
assert_line_index(2)
2262+
assert_whole_lines(['def hoge', ' 67890', ' 12345', 'end'])
2263+
assert_byte_pointer_size(' 123')
2264+
assert_cursor(5)
2265+
assert_cursor_max(7)
2266+
assert_line(' 12345')
2267+
@line_editor.__send__(:ed_search_next_history, "\C-n".ord)
2268+
assert_line_index(1)
2269+
assert_whole_lines(['def foo', ' 12345', 'end'])
2270+
assert_byte_pointer_size(' 123')
2271+
assert_cursor(5)
2272+
assert_cursor_max(7)
2273+
assert_line(' 12345')
2274+
@line_editor.__send__(:ed_search_next_history, "\C-n".ord)
2275+
assert_line_index(1)
2276+
assert_whole_lines(['def foo', ' 12345', 'end'])
2277+
assert_byte_pointer_size(' 123')
2278+
assert_cursor(5)
2279+
assert_cursor_max(7)
2280+
assert_line(' 12345')
2281+
end
2282+
22362283
=begin # TODO: move KeyStroke instance from Reline to LineEditor
22372284
def test_key_delete
22382285
input_keys('ab')

0 commit comments

Comments
 (0)
0