feat: add context-aware ask keymaps
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user