-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve key binding match/matching check
- Loading branch information
Showing
17 changed files
with
198 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
class Reline::KeyActor::Base | ||
MAPPING = Array.new(256) | ||
def initialize(mapping = []) | ||
@mapping = mapping | ||
@matching_bytes = {} | ||
@key_bindings = {} | ||
end | ||
|
||
def get_method(key) | ||
self.class::MAPPING[key] | ||
@mapping[key] | ||
end | ||
|
||
def add(key, func) | ||
(1...key.size).each do |size| | ||
@matching_bytes[key.take(size)] = true | ||
end | ||
@key_bindings[key] = func | ||
end | ||
|
||
def matching?(key) | ||
@matching_bytes[key] | ||
end | ||
|
||
def initialize | ||
@default_key_bindings = {} | ||
def get(key) | ||
@key_bindings[key] | ||
end | ||
|
||
def default_key_bindings | ||
@default_key_bindings | ||
def clear | ||
@matching_bytes.clear | ||
@key_bindings.clear | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Reline::KeyActor::Composite | ||
def initialize(key_actors) | ||
@key_actors = key_actors | ||
end | ||
|
||
def matching?(key) | ||
@key_actors.any? { |key_actor| key_actor.matching?(key) } | ||
end | ||
|
||
def get(key) | ||
@key_actors.each do |key_actor| | ||
func = key_actor.get(key) | ||
return func if func | ||
end | ||
nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.