feat: add context-aware ask keymaps

This commit is contained in:
Erik Kotsiuba
2026-05-06 12:44:37 +02:00
parent 3672ada13f
commit 808b62cc77
18 changed files with 1158 additions and 444 deletions
+16
View File
@@ -172,6 +172,7 @@ function renderController(
}
function handleControllerInput(controller: AskFlowController, data: string) {
controller.editor.disableSubmit = !isNativeEditorSubmitEnabled(controller);
const command = getInputCommand(
controller.state,
controller.config,
@@ -185,6 +186,16 @@ function handleControllerInput(controller: AskFlowController, data: string) {
handleNavigationCommand(controller, command);
}
function isNativeEditorSubmitEnabled(controller: AskFlowController): boolean {
if (controller.state.view.kind === "input") {
return controller.config.keymaps.editor.submit.includes("enter");
}
if (controller.state.view.kind === "note") {
return controller.config.keymaps.noteEditor.save.includes("enter");
}
return true;
}
function handleEditingCommand(
controller: AskFlowController,
command: AskInputCommand,
@@ -210,6 +221,10 @@ function handleEditingCommand(
closeEditor(controller);
return;
}
if (command.kind === "editSubmit") {
submitEditor(controller, controller.editor.getText());
return;
}
if (command.kind === "delegateToEditor") {
controller.editor.handleInput(data);
refresh(controller);
@@ -270,6 +285,7 @@ function handleNavigationCommand(
case "editMoveTab":
case "editMoveOption":
case "editClose":
case "editSubmit":
case "delegateToEditor":
return;
default: