diff options
| author | aycabta <aycabta@gmail.com> | 2019-05-21 17:46:31 +0900 |
|---|---|---|
| committer | aycabta <aycabta@gmail.com> | 2019-05-21 17:46:41 +0900 |
| commit | 6d93baaedd0e9819d4ddb6637b2d3d539f1fa210 (patch) | |
| tree | a77b588bf49957a1c8f069740801443e97d20b66 | |
| parent | 8c004c71235c5ee8b2d4846672788d3089f3e884 (diff) | |
Support DEL key
| -rw-r--r-- | lib/reline.rb | 6 | ||||
| -rw-r--r-- | lib/reline/line_editor.rb | 6 | ||||
| -rw-r--r-- | test/reline/test_key_actor_emacs.rb | 25 |
3 files changed, 35 insertions, 2 deletions
diff --git a/lib/reline.rb b/lib/reline.rb index a5acc52f03..258edcd457 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -299,7 +299,8 @@ module Reline [224, 72] => :ed_prev_history, # ↑ [224, 80] => :ed_next_history, # ↓ [224, 77] => :ed_next_char, # → - [224, 75] => :ed_prev_char # ← + [224, 75] => :ed_prev_char, # ← + [224, 83] => :key_delete # Del } } else @@ -308,7 +309,8 @@ module Reline [27, 91, 65] => :ed_prev_history, # ↑ [27, 91, 66] => :ed_next_history, # ↓ [27, 91, 67] => :ed_next_char, # → - [27, 91, 68] => :ed_prev_char # ← + [27, 91, 68] => :ed_prev_char, # ← + [27, 91, 51, 126] => :key_delete # Del } } end diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 9df263aba1..fb7e377dcf 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -761,6 +761,12 @@ class Reline::LineEditor } end + private def key_delete(key) + if @config.editing_mode_is?(:vi_insert, :emacs) + ed_delete_next_char(key) + end + end + private def ed_insert(key) if key.instance_of?(String) width = Reline::Unicode.get_mbchar_width(key) diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 535906ea24..11ae53b971 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1180,4 +1180,29 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase assert_cursor(0) assert_cursor_max(3) end + +=begin # TODO: move KeyStroke instance from Reline to LineEditor + def test_key_delete + input_keys('ab') + assert_byte_pointer_size('ab') + assert_cursor(2) + assert_cursor_max(2) + assert_line('ab') + [27, 91, 51, 126].each do |key| + @line_editor.input_key(key) + end + assert_byte_pointer_size('ab') + assert_cursor(2) + assert_cursor_max(2) + assert_line('ab') + input_keys("\C-b") + [27, 91, 51, 126].each do |key| + @line_editor.input_key(key) + end + assert_byte_pointer_size('a') + assert_cursor(1) + assert_cursor_max(1) + assert_line('a') + end +=end end |
