diff options
author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-06-03 22:14:57 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-06-03 13:15:05 +0000 |
commit | 91d4a7ae0c719697db7dd6dd64ca664b60c9de04 (patch) | |
tree | 66e2d8d2a077c79f8acfec1feccbce48e6805df0 /lib/reline.rb | |
parent | 631449ac6b9336dfce577a786aff7eca0b8abcf1 (diff) | |
download | ruby-91d4a7ae0c719697db7dd6dd64ca664b60c9de04.tar.gz |
[ruby/reline] Improve key binding match/matching check
(https://github.com/ruby/reline/pull/709)
* Improve key binding match/matching check
* Rename key_actors to default_key_bindings
* Make key_stroke.expand always return a value
* Update add_default_key_binding to use a add_default_key_binding_by_keymap internally
Co-authored-by: Stan Lo <stan001212@gmail.com>
---------
https://github.com/ruby/reline/commit/353ec236e2
Co-authored-by: Stan Lo <stan001212@gmail.com>
Diffstat (limited to 'lib/reline.rb')
-rw-r--r-- | lib/reline.rb | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/reline.rb b/lib/reline.rb index 796e637e85..33a1cfc625 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -19,20 +19,10 @@ module Reline class ConfigEncodingConversionError < StandardError; end Key = Struct.new(:char, :combined_char, :with_meta) do - def match?(other) - case other - when Reline::Key - (other.char.nil? or char.nil? or char == other.char) and - (other.combined_char.nil? or combined_char.nil? or combined_char == other.combined_char) and - (other.with_meta.nil? or with_meta.nil? or with_meta == other.with_meta) - when Integer, Symbol - (combined_char and combined_char == other) or - (combined_char.nil? and char and char == other) - else - false - end + # For dialog_proc `key.match?(dialog.name)` + def match?(sym) + combined_char.is_a?(Symbol) && combined_char == sym end - alias_method :==, :match? end CursorPos = Struct.new(:x, :y) DialogRenderInfo = Struct.new( @@ -400,9 +390,8 @@ module Reline end case result when :matched - expanded = key_stroke.expand(buffer).map{ |expanded_c| - Reline::Key.new(expanded_c, expanded_c, false) - } + expanded, rest_bytes = key_stroke.expand(buffer) + rest_bytes.reverse_each { |c| io_gate.ungetc(c) } block.(expanded) break when :matching @@ -416,9 +405,8 @@ module Reline if buffer.size == 1 and c == "\e".ord read_escaped_key(keyseq_timeout, c, block) else - expanded = buffer.map{ |expanded_c| - Reline::Key.new(expanded_c, expanded_c, false) - } + expanded, rest_bytes = key_stroke.expand(buffer) + rest_bytes.reverse_each { |c| io_gate.ungetc(c) } block.(expanded) end break @@ -442,9 +430,8 @@ module Reline return :next when :matched buffer << succ_c - expanded = key_stroke.expand(buffer).map{ |expanded_c| - Reline::Key.new(expanded_c, expanded_c, false) - } + expanded, rest_bytes = key_stroke.expand(buffer) + rest_bytes.reverse_each { |c| io_gate.ungetc(c) } block.(expanded) return :break end |