From e848848b58adbf7b5d60537a89cc8de4c48de15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Sun, 11 Feb 2024 10:03:47 +0000 Subject: [PATCH] [ruby/reline] C for vi mode (https://github.com/ruby/reline/pull/472) https://github.com/ruby/reline/commit/d197be7c44 --- lib/reline/line_editor.rb | 7 +++++++ test/reline/test_key_actor_vi.rb | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 57306673cd..b7cc6b747d 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2563,6 +2563,13 @@ class Reline::LineEditor end alias_method :kill_line, :ed_kill_line + # Editline:: +vi_change_to_eol+ (vi command: +C+) + Kill and change from the cursor to the end of the line. + private def vi_change_to_eol(key) + ed_kill_line(key) + + @config.editing_mode = :vi_insert + end + # Editline:: +vi-kill-line-prev+ (vi: +Ctrl-U+) Delete the string from the # beginning of the edit buffer to the cursor and save it to the # cut buffer. diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index 20630e5809..7c924d1963 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -1455,6 +1455,16 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase assert_line('c') end + def test_vi_change_to_eol + input_keys("abcdef\C-[2hC") + assert_line("abc") + input_keys("\C-[0C") + assert_line("") + assert_cursor(0) + assert_cursor_max(0) + assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode) + end + def test_vi_motion_operators assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)