summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2024-06-18 23:57:15 +0900
committergit <[email protected]>2024-06-18 14:57:19 +0000
commitc2e2c5975d576076bb3e77524d5458d28e761742 (patch)
tree62d5bb90237fd398e018a2e1409a36440b8af004
parentb499356307139e80a414d9ddb3a7f14dadf0eda4 (diff)
[ruby/reline] Fix vi_yank or vi_delete_meta copies nil bug
(https://github.com/ruby/reline/pull/726) https://github.com/ruby/reline/commit/46b30b07c9
-rw-r--r--lib/reline/line_editor.rb6
-rw-r--r--test/reline/test_key_actor_vi.rb14
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index d659378acd..439dbb9727 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2259,9 +2259,11 @@ class Reline::LineEditor
line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff)
elsif byte_pointer_diff < 0
line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
+ else
+ return
end
copy_for_vi(cut)
- set_current_line(line || '', @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
+ set_current_line(line, @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
end
private def vi_yank(key, arg: nil)
@@ -2280,6 +2282,8 @@ class Reline::LineEditor
cut = current_line.byteslice(@byte_pointer, byte_pointer_diff)
elsif byte_pointer_diff < 0
cut = current_line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
+ else
+ return
end
copy_for_vi(cut)
end
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index 1288b9aaa5..07ca873ce3 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -738,6 +738,13 @@ class Reline::ViInsertTest < Reline::TestCase
assert_line_around_cursor('aaa ', 'ddd eee')
end
+ def test_vi_delete_meta_nothing
+ input_keys("foo\C-[0")
+ assert_line_around_cursor('', 'foo')
+ input_keys('dhp')
+ assert_line_around_cursor('', 'foo')
+ end
+
def test_vi_delete_meta_with_vi_next_word_at_eol
input_keys("foo bar\C-[0w")
assert_line_around_cursor('foo ', 'bar')
@@ -848,6 +855,13 @@ class Reline::ViInsertTest < Reline::TestCase
assert_line_around_cursor('foofofoofoo barba', 'ro barbar')
end
+ def test_vi_yank_nothing
+ input_keys("foo\C-[0")
+ assert_line_around_cursor('', 'foo')
+ input_keys('yhp')
+ assert_line_around_cursor('', 'foo')
+ end
+
def test_vi_end_word_with_operator
input_keys("foo bar\C-[0")
assert_line_around_cursor('', 'foo bar')