fix: allow empty editor navigation shortcuts
This commit is contained in:
@@ -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
@@ -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" };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user