diff --git a/lib/reline/key_actor/vi_command.rb b/lib/reline/key_actor/vi_command.rb index 130fcb04a6..5a56fe5694 100644 --- a/lib/reline/key_actor/vi_command.rb +++ b/lib/reline/key_actor/vi_command.rb @@ -189,7 +189,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base # 93 ] :ed_unassigned, # 94 ^ - :ed_move_to_beg, + :vi_first_print, # 95 _ :vi_history_word, # 96 ` diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f3c24d9e02..6446879312 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1016,8 +1016,12 @@ class Reline::LineEditor ed_prev_char(key, arg: arg) if arg > 0 end + private def vi_first_print(key) + @byte_pointer, @cursor = Reline::Unicode.vi_first_print(@line) + end + private def ed_move_to_beg(key) - @byte_pointer, @cursor = Reline::Unicode.ed_move_to_begin(@line) + @byte_pointer = @cursor = 0 end private def ed_move_to_end(key) diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb index 448bdf1b52..5523d4fa31 100644 --- a/lib/reline/unicode.rb +++ b/lib/reline/unicode.rb @@ -407,7 +407,7 @@ class Reline::Unicode [byte_size, width] end - def self.ed_move_to_begin(line) + def self.vi_first_print(line) width = 0 byte_size = 0 while (line.bytesize - 1) > byte_size diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 81bff17967..ffd066f80f 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -305,6 +305,17 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_line('aABC012abcd') end + def test_ed_move_to_beg_with_blank + input_keys(' abc') + assert_byte_pointer_size(' abc') + assert_cursor(5) + assert_cursor_max(5) + input_keys("\C-a", false) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + end + def test_ed_move_to_end input_keys('abd') assert_byte_pointer_size('abd') diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index f5ceda05a6..52362e5893 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -988,7 +988,7 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_line('abcde foo_bar_baz ABCDE') end - def test_ed_move_to_beg + def test_vi_first_print input_keys("abcde\C-[^") assert_byte_pointer_size('') assert_cursor(0) @@ -1005,6 +1005,23 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_cursor_max(17) end + def test_ed_move_to_beg + input_keys("abcde\C-[0") + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + input_keys("0\C-ki") + input_keys(" abcde\C-[0") + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(6) + input_keys("0\C-ki") + input_keys(" abcde ABCDE \C-[0") + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(17) + end + def test_vi_delete_meta input_keys("aaa bbb ccc ddd eee\C-[02w") assert_byte_pointer_size('aaa bbb ')