diff options
-rw-r--r-- | lib/reline/line_editor.rb | 14 | ||||
-rw-r--r-- | test/reline/test_key_actor_vi.rb | 18 |
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 1387bfa876..6890fa544a 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2087,12 +2087,17 @@ class Reline::LineEditor @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg) } end - private def search_next_char(key, arg) + private def vi_to_next_char(key, arg: 1) + @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg, true) } + end + + private def search_next_char(key, arg, need_prev_char = false) if key.instance_of?(String) inputed_char = key else inputed_char = key.chr end + prev_total = nil total = nil found = false @line.byteslice(@byte_pointer..-1).grapheme_clusters.each do |mbchar| @@ -2110,13 +2115,18 @@ class Reline::LineEditor end end width = Reline::Unicode.get_mbchar_width(mbchar) + prev_total = total total = [total.first + mbchar.bytesize, total.last + width] end end - if found and total + if not need_prev_char and found and total byte_size, width = total @byte_pointer += byte_size @cursor += width + elsif need_prev_char and found and prev_total + byte_size, width = prev_total + @byte_pointer += byte_size + @cursor += width end @waiting_proc = nil end diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index b8ab160ff4..d23bdb7769 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -633,6 +633,24 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_cursor_max(6) end + def test_vi_to_next_char + input_keys("abcdef\C-[0") + assert_line('abcdef') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(6) + input_keys('tz') + assert_line('abcdef') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(6) + input_keys('te') + assert_line('abcdef') + assert_byte_pointer_size('abc') + assert_cursor(3) + assert_cursor_max(6) + end + def test_vi_delete_next_char input_keys("abc\C-[h") assert_byte_pointer_size('a') |