diff options
author | aycabta <[email protected]> | 2021-09-27 04:24:06 +0900 |
---|---|---|
committer | aycabta <[email protected]> | 2021-12-24 18:23:28 +0900 |
commit | bad1e153d485cf7b68981a78e78e23c3f118c5a8 (patch) | |
tree | 69751bc2471c7c492b597e9053be5c176d152e1c | |
parent | 6c3cc9c58ab95e963d6255d719e2248cafef7b49 (diff) |
[ruby/reline] Implement em_kill_line
https://github.com/ruby/reline/commit/9fca6ceb45
-rw-r--r-- | lib/reline/line_editor.rb | 11 | ||||
-rw-r--r-- | test/reline/test_key_actor_emacs.rb | 28 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index a1f12f2cfa..d94821e6fe 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -2632,6 +2632,17 @@ class Reline::LineEditor end alias_method :unix_line_discard, :vi_kill_line_prev + private def em_kill_line(key) + if @line.size > 0 + @kill_ring.append(@line.dup, true) + @line.clear + @byte_pointer = 0 + @cursor_max = 0 + @cursor = 0 + end + end + alias_method :kill_whole_line, :em_kill_line + private def em_delete(key) if (not @is_multiline and @line.empty?) or (@is_multiline and @line.empty? and @buffer_of_lines.size == 1) @line = nil diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index a9033a85b5..a5fdf247c8 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -254,6 +254,34 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_line('ab') end + def test_em_kill_line + @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + input_keys('abc') + @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + input_keys('abc') + input_keys("\C-b", false) + @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + input_keys('abc') + input_keys("\C-a", false) + @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + end + def test_ed_move_to_beg input_keys('abd') assert_byte_pointer_size('abd') |