Class: Charming::Controller::KeyDispatch

Inherits:
Object
  • Object
show all
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:

  1. Command palette (when open) consumes everything.
  2. 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.
  3. Global key bindings.
  4. An overlay focus scope (a pushed modal) captures all remaining keys.
  5. 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

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

#callObject

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 overlay_response if overlay?
  return sidebar_response if sidebar_focused?
  return binding_response(content_action) if content_action
  return response if component_or_ring_claimed?

  nil
end