diff options
author | Étienne Barrié <etienne.barrie@gmail.com> | 2023-03-24 15:29:46 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-04-05 08:59:12 +0900 |
commit | 52ff2ce9da2958cd59d93a063b24345c4110c65c (patch) | |
tree | 95343f6f263a8eb64ef4d7dc438dab24651a751f /test/reline | |
parent | bb927acd3bd3a5a5797587bc4201724235ed26b5 (diff) | |
download | ruby-52ff2ce9da2958cd59d93a063b24345c4110c65c.tar.gz |
Use `em_delete` in `key_delete` (#504)
* Test existing behavior
Typing Ctrl-D ends editing but typing <Del> does not.
Also renamed a test that is not testing ed_delete_next_char but
key_delete.
* Check if line empty first in em_delete
By distributivity of AND over OR, we can factor out this condition. This
will make the next commit simpler.
* Use em_delete in key_delete
When the editing mode is emacs, use `em_delete` in `key_delete`. We need
to add a condition though to `em_delete`, because it implements both
`delete-char` and `end-of-file`. We only want the `end-of-file` behavior
is the key is really Ctrl-D.
This matches the behavior of the <Del> key with readline, i.e. deleting
the next character if there is one, but not moving the cursor, while not
finishing the editing if there are no characters.
Diffstat (limited to 'test/reline')
-rw-r--r-- | test/reline/test_key_actor_emacs.rb | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 40b26e5058..18a2448539 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -428,6 +428,12 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_line("き\u3099") end + def test_em_delete_ends_editing + input_keys("\C-d") # quit from inputing + assert_line(nil) + assert(@line_editor.finished?) + end + def test_ed_clear_screen refute(@line_editor.instance_variable_get(:@cleared)) input_keys("\C-l", false) @@ -449,7 +455,7 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_line('abc') end - def test_ed_delete_next_char + def test_key_delete input_keys('abc') assert_cursor(3) assert_cursor_max(3) @@ -459,6 +465,25 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_line('abc') end + def test_key_delete_does_not_end_editing + @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false)) + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + refute(@line_editor.finished?) + end + + def test_key_delete_preserves_cursor + input_keys('abc') + input_keys("\C-b", false) + assert_cursor(2) + assert_cursor_max(3) + @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false)) + assert_cursor(2) + assert_cursor_max(2) + assert_line('ab') + end + def test_em_next_word assert_byte_pointer_size('') assert_cursor(0) |