-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve key binding match/matching check #709
Conversation
a6a180a
to
119950b
Compare
119950b
to
265959e
Compare
@@ -19,20 +19,10 @@ module Reline | |||
class ConfigEncodingConversionError < StandardError; end | |||
|
|||
Key = Struct.new(:char, :combined_char, :with_meta) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we also convert this into a normal class?
end | ||
|
||
def add_oneshot_key_binding(keystroke, target) | ||
@oneshot_key_bindings[keystroke] = target | ||
# IRB sets invalid keystroke [Reline::Key]. We should ignore it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we removed that from IRB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet.
Even if we remove it, we need to support [Reline::Key.new(nil, 0xE4, true)]
for a while, not to break an environment that new Reline is installed but IRB is not updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'm aware of that and I'm not arguing we need to change the approach here 🙂 I just hadn't see any related PR on IRB so want to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened ruby/irb#963
…ymap internally Co-authored-by: Stan Lo <stan001212@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't test the changes manually, but they look good to me 👍
(ruby/reline#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> --------- ruby/reline@353ec236e2 Co-authored-by: Stan Lo <stan001212@gmail.com>
First step of #708
This will make
:matched
:matching
check simple and fast, especially after we merge MAPPING(size==256 array) and key_bindings(small hash)Structure
Composite key binding
KeyStroke#expand
When key bindings is
{ 'abc' => :foo, 'ab' => :bar, 'xy' => :baz }
,abxy
should be[:bar, :baz]
.Old implementation will expand
abx
to[Key(:bar), Key('x')]
but it should beexpanded: [Key(:bar)], rest_bytes: ['x']
. The rest bytesx
could be part ofxy
.