fix: allow empty editor navigation shortcuts

This commit is contained in:
Erik Kotsiuba
2026-04-19 18:19:04 +02:00
parent 050e8800cd
commit 5d7ccc8ce2
5 changed files with 113 additions and 29 deletions
+5 -1
View File
@@ -105,7 +105,11 @@ function renderController(
}
function handleControllerInput(controller: AskFlowController, data: string) {
const command = getInputCommand(controller.state, data);
const command = getInputCommand(
controller.state,
data,
isEditingView(controller.state) ? controller.editor.getText() : ""
);
if (isEditingView(controller.state)) {
handleEditingCommand(controller, command, data);
return;
+21 -3
View File
@@ -21,14 +21,15 @@ export type AskInputCommand =
export function getInputCommand(
state: AskState,
data: string
data: string,
editingText = ""
): AskInputCommand {
if (matchesKey(data, Key.ctrl("c"))) {
return { kind: "dismiss" };
}
if (state.view.kind === "input" || state.view.kind === "note") {
return getEditingInputCommand(data);
return getEditingInputCommand(data, editingText);
}
return getNavigationInputCommand(data);
@@ -46,10 +47,27 @@ export function formatKeybindingLabel(key: string): string {
.join("+");
}
function getEditingInputCommand(data: string): AskInputCommand {
function getEditingInputCommand(
data: string,
editingText: string
): AskInputCommand {
if (matchesKey(data, Key.escape)) {
return { kind: "editClose" };
}
if (editingText.length === 0) {
if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {
return { kind: "editMoveTab", delta: 1 };
}
if (matchesKey(data, Key.shift("tab")) || matchesKey(data, Key.left)) {
return { kind: "editMoveTab", delta: -1 };
}
if (matchesKey(data, Key.up)) {
return { kind: "editMoveOption", delta: -1 };
}
if (matchesKey(data, Key.down)) {
return { kind: "editMoveOption", delta: 1 };
}
}
return { kind: "delegateToEditor" };
}