Class: Charming::Controller::KeyDispatch
- Inherits:
-
Object
- Object
- Charming::Controller::KeyDispatch
- Defined in:
- lib/charming/controller/key_dispatch.rb
Overview
KeyDispatch resolves which handler claims a key event — the capture/bubble ladder a browser would own in a web MVC app. Priority order:
- Command palette (when open) consumes everything.
- A focused text-capturing component (TextInput, TextArea, Form, …) gets printable characters BEFORE key bindings — typing "q" into a field must insert a q, not quit the app.
- Global key bindings.
- An overlay focus scope (a pushed modal) captures all remaining keys.
- Sidebar keys (when focused), content bindings, then the focused component — which sees Tab before ring traversal so forms can do field navigation.
Tiers differ in how they terminate: the palette, overlay, sidebar, and binding tiers consume the key outright once their condition holds, while the component tiers only consume it when the component reports :handled and otherwise let it fall through to the next tier.
Instance Method Summary collapse
-
#call ⇒ Object
Runs the ladder for the controller's current event.
-
#initialize(controller) ⇒ KeyDispatch
constructor
A new instance of KeyDispatch.
Constructor Details
#initialize(controller) ⇒ KeyDispatch
Returns a new instance of KeyDispatch.
22 23 24 |
# File 'lib/charming/controller/key_dispatch.rb', line 22 def initialize(controller) @controller = controller end |
Instance Method Details
#call ⇒ Object
Runs the ladder for the controller's current event. Returns the winning tier's response, or nil when no tier claims the key.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/charming/controller/key_dispatch.rb', line 28 def call return palette_response if palette_open? return response if typed_text_claimed? return binding_response(global_action) if global_action return if return if return binding_response(content_action) if content_action return response if component_or_ring_claimed? nil end |