fix: handle composer key actions with on_action on the root
bind_keys actions dispatch through the element tree; nextCommand only serves keys.json. Register on_action for all seven composer actions. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
2ce1b45ee4
commit
e7deca480a
1 file changed
+27
-7
@@ -171,13 +171,7 @@ export default class Composer extends View {
|
||||
for (;;) {
|
||||
const command = await nextCommand();
|
||||
if (command === "focus") this.textarea.focus();
|
||||
if (command === "up") this.arrow(-1, cx);
|
||||
if (command === "down") this.arrow(1, cx);
|
||||
if (command === "accept") this.acceptFromKey(cx);
|
||||
if (command === "panel") this.intent({ key: "r", ctrl: true }, cx);
|
||||
if (command === "send_now") this.intent({ key: "enter", ctrl: true }, cx);
|
||||
if (command === "hold") this.intent({ key: "enter", alt: true }, cx);
|
||||
if (command === "escape") this.intent({ key: "escape" }, cx);
|
||||
this.runAction(command, cx);
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
@@ -482,6 +476,22 @@ export default class Composer extends View {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** One of the composer's bound actions (the names bind_keys uses, without the prefix). */
|
||||
runAction(command, cx) {
|
||||
// The same press may arrive twice (element action and nextCommand); the
|
||||
// second delivery within 40 ms is the same key.
|
||||
const now = Date.now();
|
||||
if (this.lastAction && this.lastAction.command === command && now - this.lastAction.at < 40) return;
|
||||
this.lastAction = { command, at: now };
|
||||
if (command === "up") this.arrow(-1, cx);
|
||||
if (command === "down") this.arrow(1, cx);
|
||||
if (command === "accept") this.acceptFromKey(cx);
|
||||
if (command === "panel") this.intent({ key: "r", ctrl: true }, cx);
|
||||
if (command === "send_now") this.intent({ key: "enter", ctrl: true }, cx);
|
||||
if (command === "hold") this.intent({ key: "enter", alt: true }, cx);
|
||||
if (command === "escape") this.intent({ key: "escape" }, cx);
|
||||
}
|
||||
|
||||
/** Task 7: the history panel. Nothing to open yet. */
|
||||
openPanel() {}
|
||||
|
||||
@@ -1206,6 +1216,16 @@ export default class Composer extends View {
|
||||
.track_focus(this.handle)
|
||||
.key_context(CONTEXT)
|
||||
.on_key_down((event, cx) => this.key(event, cx))
|
||||
// Actions that cx.bind_keys dispatches reach the element tree, not
|
||||
// nextCommand() (that one only serves keys.json). The field sits inside
|
||||
// this root, so the actions arrive here.
|
||||
.on_action("ovis-composer.up", (e, cx) => this.runAction("up", cx))
|
||||
.on_action("ovis-composer.down", (e, cx) => this.runAction("down", cx))
|
||||
.on_action("ovis-composer.accept", (e, cx) => this.runAction("accept", cx))
|
||||
.on_action("ovis-composer.panel", (e, cx) => this.runAction("panel", cx))
|
||||
.on_action("ovis-composer.send_now", (e, cx) => this.runAction("send_now", cx))
|
||||
.on_action("ovis-composer.hold", (e, cx) => this.runAction("hold", cx))
|
||||
.on_action("ovis-composer.escape", (e, cx) => this.runAction("escape", cx))
|
||||
.size_full()
|
||||
.p(8)
|
||||
.gap(6)
|
||||
|
||||
Reference in new issue
Block a user