summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-12-24 21:44:09 +0900
committeraycabta <aycabta@gmail.com>2020-12-24 23:26:22 +0900
commit78421319d0401c37497f2b5df7110e92eef9f0e4 (patch)
treef30077d4490bc175318544d2a594d17dc95677bc
parent0db9842b2ca85709424d6c9c1e11caeae30dfae7 (diff)
[ruby/reline] Use #bytesize for vi_replace_char
This closes ruby/reline#228. https://github.com/ruby/reline/commit/8205fa0b00
-rw-r--r--lib/reline/line_editor.rb4
-rw-r--r--test/reline/test_key_actor_vi.rb18
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 4f32f26b63..c1564fa57e 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2478,7 +2478,7 @@ class Reline::LineEditor
byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer)
before = @line.byteslice(0, @byte_pointer)
remaining_point = @byte_pointer + byte_size
- after = @line.byteslice(remaining_point, @line.size - remaining_point)
+ after = @line.byteslice(remaining_point, @line.bytesize - remaining_point)
@line = before + k.chr + after
@cursor_max = calculate_width(@line)
@waiting_proc = nil
@@ -2489,7 +2489,7 @@ class Reline::LineEditor
end
before = @line.byteslice(0, @byte_pointer)
remaining_point = @byte_pointer + byte_size
- after = @line.byteslice(remaining_point, @line.size - remaining_point)
+ after = @line.byteslice(remaining_point, @line.bytesize - remaining_point)
replaced = k.chr * arg
@line = before + replaced + after
@byte_pointer += replaced.bytesize
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index 45a5327763..21f4e89a2d 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -615,6 +615,24 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
assert_cursor_max(6)
end
+ def test_vi_replace_char_with_mbchar
+ input_keys("あいうえお\C-[0l")
+ assert_line('あいうえお')
+ assert_byte_pointer_size('あ')
+ assert_cursor(2)
+ assert_cursor_max(10)
+ input_keys('rx')
+ assert_line('あxうえお')
+ assert_byte_pointer_size('あ')
+ assert_cursor(2)
+ assert_cursor_max(9)
+ input_keys('l2ry')
+ assert_line('あxyyお')
+ assert_byte_pointer_size('あxyy')
+ assert_cursor(5)
+ assert_cursor_max(7)
+ end
+
def test_vi_next_char
input_keys("abcdef\C-[0")
assert_line('abcdef')