Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ask-inline-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export async function askSingleQuestionWithInlineNote(
};

const handleInput = (data: string) => {
if (matchesKey(data, Key.ctrl("c"))) {
done({ cancelled: true });
return;
}

if (isNoteEditorOpen) {
if (matchesKey(data, Key.tab) || matchesKey(data, Key.escape)) {
isNoteEditorOpen = false;
Expand Down
5 changes: 5 additions & 0 deletions src/ask-tabs-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ export async function askQuestionsWithTabs(
};

const handleInput = (data: string) => {
if (matchesKey(data, Key.ctrl("c"))) {
done(createTabsUiStateSnapshot(true, selectedOptionIndexesByQuestion, noteByQuestionByOption));
return;
}

if (isNoteEditorOpen) {
if (matchesKey(data, Key.tab) || matchesKey(data, Key.escape)) {
isNoteEditorOpen = false;
Expand Down
85 changes: 85 additions & 0 deletions test/ask-ui-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ describe("askSingleQuestionWithInlineNote interactive branches", () => {
expect(result).toEqual({ selectedOptions: [], customInput: "custom-flow" });
});

it("cancels single-question flow on Ctrl-C, including from note editor", async () => {
const ui = {
custom: async (factory: any) => {
const tui = { requestRender() {} };
const theme = createFakeTheme();
let result: any;
const done = (value: any) => {
result = value;
};

const component = await factory(tui, theme, {}, done);
component.render(40);
component.handleInput(" ");
component.handleInput("draft");
component.handleInput("");
return result;
},
} as unknown as ExtensionUIContext;

const result = await askSingleQuestionWithInlineNote(ui, {
question: "Choose one",
options: [{ label: "A" }, { label: "B" }],
});

expect(result).toEqual({ selectedOptions: [] });
});

it("handles navigation, inline edit exit, invalidate, and cancel", async () => {
const ui = {
custom: async (factory: any) => {
Expand Down Expand Up @@ -250,6 +277,64 @@ describe("askQuestionsWithTabs interactive branches", () => {
});
});

it("cancels tab flow on Ctrl-C from note editor", async () => {
const ui = {
custom: async (factory: any) => {
const tui = { requestRender() {} };
const theme = createFakeTheme();
let result: any;
const done = (value: any) => {
result = value;
};

const component = await factory(tui, theme, {}, done);
component.render(40);
component.handleInput(" ");
component.handleInput("memo");
component.handleInput("");
return result;
},
} as unknown as ExtensionUIContext;

const result = await askQuestionsWithTabs(ui, [
{ id: "q1", question: "Question 1", options: [{ label: "A" }, { label: "B" }] },
{ id: "q2", question: "Question 2", options: [{ label: "C" }, { label: "D" }] },
]);

expect(result).toEqual({
cancelled: true,
selections: [{ selectedOptions: [] }, { selectedOptions: [] }],
});
});

it("cancels tab flow on Ctrl-C from submit tab", async () => {
const ui = {
custom: async (factory: any) => {
const tui = { requestRender() {} };
const theme = createFakeTheme();
let result: any;
const done = (value: any) => {
result = value;
};

const component = await factory(tui, theme, {}, done);
component.handleInput("\r");
component.handleInput("\u001b[C");
component.handleInput("\u0003");
return result;
},
} as unknown as ExtensionUIContext;

const result = await askQuestionsWithTabs(ui, [
{ id: "q1", question: "Question 1", options: [{ label: "A" }] },
]);

expect(result).toEqual({
cancelled: true,
selections: [{ selectedOptions: [] }],
});
});

it("covers submit-tab validation warning and cancel via Esc", async () => {
const ui = {
custom: async (factory: any) => {
Expand Down
Loading