diff options
author | Étienne Barrié <[email protected]> | 2023-03-24 15:29:46 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-04-05 08:59:12 +0900 |
commit | 52ff2ce9da2958cd59d93a063b24345c4110c65c (patch) | |
tree | 95343f6f263a8eb64ef4d7dc438dab24651a751f /lib/reline/line_editor.rb | |
parent | bb927acd3bd3a5a5797587bc4201724235ed26b5 (diff) |
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 'lib/reline/line_editor.rb')
-rw-r--r-- | lib/reline/line_editor.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 6e34c28b53..6e2bd59f05 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1940,8 +1940,10 @@ class Reline::LineEditor end private def key_delete(key) - if @config.editing_mode_is?(:vi_insert, :emacs) + if @config.editing_mode_is?(:vi_insert) ed_delete_next_char(key) + elsif @config.editing_mode_is?(:emacs) + em_delete(key) end end @@ -2647,7 +2649,7 @@ class Reline::LineEditor 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) + if @line.empty? and (not @is_multiline or @buffer_of_lines.size == 1) and key == "\C-d".ord @line = nil if @buffer_of_lines.size > 1 scroll_down(@highest_in_all - @first_line_started_from) |