diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index dda602e155..1387bfa876 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1890,6 +1890,16 @@ class Reline::LineEditor end end + private def vi_insert_at_bol(key) + ed_move_to_beg(key) + @config.editing_mode = :vi_insert + end + + private def vi_add_at_eol(key) + ed_move_to_end(key) + @config.editing_mode = :vi_insert + end + private def ed_delete_prev_char(key, arg: 1) deleted = '' arg.times do diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index d46d784d1b..b8ab160ff4 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -56,6 +56,42 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) end + def test_vi_insert_at_bol + input_keys('I') + assert_line('I') + assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) + input_keys("12345\C-[hh") + assert_line('I12345') + assert_byte_pointer_size('I12') + assert_cursor(3) + assert_cursor_max(6) + assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode) + input_keys('I') + assert_line('I12345') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(6) + assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) + end + + def test_vi_add_at_eol + input_keys('A') + assert_line('A') + assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) + input_keys("12345\C-[hh") + assert_line('A12345') + assert_byte_pointer_size('A12') + assert_cursor(3) + assert_cursor_max(6) + assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode) + input_keys('A') + assert_line('A12345') + assert_byte_pointer_size('A12345') + assert_cursor(6) + assert_cursor_max(6) + assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) + end + def test_ed_insert_one input_keys('a') assert_line('a')