Skip to content

Commit

Permalink
[ruby/reline] Use #bytesize for vi_replace_char
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Dec 24, 2020
1 parent 0db9842 commit 7842131
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/reline/line_editor.rb
Expand Up @@ -2478,7 +2478,7 @@ def finish
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
Expand All @@ -2489,7 +2489,7 @@ def finish
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
Expand Down
18 changes: 18 additions & 0 deletions test/reline/test_key_actor_vi.rb
Expand Up @@ -615,6 +615,24 @@ def test_vi_replace_char
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')
Expand Down

0 comments on commit 7842131

Please sign in to comment.