Skip to content

Commit 46b30b0

Browse files
authored
Fix vi_yank or vi_delete_meta copies nil bug (#726)
1 parent aff1d85 commit 46b30b0

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎lib/reline/line_editor.rb‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,9 +2259,11 @@ def finish
22592259
line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff)
22602260
elsif byte_pointer_diff < 0
22612261
line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2262+
else
2263+
return
22622264
end
22632265
copy_for_vi(cut)
2264-
set_current_line(line || '', @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
2266+
set_current_line(line, @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
22652267
end
22662268

22672269
private def vi_yank(key, arg: nil)
@@ -2280,6 +2282,8 @@ def finish
22802282
cut = current_line.byteslice(@byte_pointer, byte_pointer_diff)
22812283
elsif byte_pointer_diff < 0
22822284
cut = current_line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2285+
else
2286+
return
22832287
end
22842288
copy_for_vi(cut)
22852289
end

‎test/reline/test_key_actor_vi.rb‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,13 @@ def test_vi_delete_meta
738738
assert_line_around_cursor('aaa ', 'ddd eee')
739739
end
740740

741+
def test_vi_delete_meta_nothing
742+
input_keys("foo\C-[0")
743+
assert_line_around_cursor('', 'foo')
744+
input_keys('dhp')
745+
assert_line_around_cursor('', 'foo')
746+
end
747+
741748
def test_vi_delete_meta_with_vi_next_word_at_eol
742749
input_keys("foo bar\C-[0w")
743750
assert_line_around_cursor('foo ', 'bar')
@@ -848,6 +855,13 @@ def test_vi_yank
848855
assert_line_around_cursor('foofofoofoo barba', 'ro barbar')
849856
end
850857

858+
def test_vi_yank_nothing
859+
input_keys("foo\C-[0")
860+
assert_line_around_cursor('', 'foo')
861+
input_keys('yhp')
862+
assert_line_around_cursor('', 'foo')
863+
end
864+
851865
def test_vi_end_word_with_operator
852866
input_keys("foo bar\C-[0")
853867
assert_line_around_cursor('', 'foo bar')

0 commit comments

Comments
 (0)