summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/reline/line_editor.rb6
-rw-r--r--test/reline/test_key_actor_emacs.rb27
2 files changed, 30 insertions, 3 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)
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)