Skip to content

Commit f6beb9b

Browse files
committed
Count the editor failure dialog as an open dialog, so shortcuts, pane focus and the preset choices leave it alone
1 parent 4857dd0 commit f6beb9b

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

‎src/web/ui/app.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ const messageOf = (error: unknown): string => (error instanceof Error ? error.me
711711
/** "Open in editor": opens the selected local worktree; a right-click, enabled or not, edits the command. */
712712
const EditorControl = ({ client, view }: { client: HubClient; view: View }) => {
713713
const [pending, setPending] = useState(false);
714-
const [failure, setFailure] = useState<EditorFailure | null>(null);
714+
const failure = view.editorFailure.value;
715715
const [editing, setEditing] = useState(false);
716716
const worktree = view.worktree.value;
717717
const command = client.store.editor.value;
@@ -734,7 +734,7 @@ const EditorControl = ({ client, view }: { client: HubClient; view: View }) => {
734734
.openEditor(worktree)
735735
.catch((error: unknown) => {
736736
const code = error instanceof RequestError ? error.code : null;
737-
setFailure(editorFailure(code, messageOf(error), sent));
737+
view.editorFailure.value = editorFailure(code, messageOf(error), sent);
738738
})
739739
.finally(() => {
740740
setPending(false);
@@ -773,7 +773,7 @@ const EditorControl = ({ client, view }: { client: HubClient; view: View }) => {
773773
<EditorDialog
774774
failure={failure}
775775
onClose={() => {
776-
setFailure(null);
776+
view.editorFailure.value = null;
777777
}}
778778
/>
779779
)}

‎src/web/ui/view.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '../layout/index.js';
2626
import type { Box, TerminalManager } from '../terminals/index.js';
2727
import { closeTargets, needsConfirm } from './closing.js';
28+
import type { EditorFailure } from './editor.js';
2829
import { hostAction, Latest, offeredRepos, type HostAction } from './hosts.js';
2930
import { keymap, type Action } from './keymap.js';
3031
import { pickerValid, type PickerContext, type PickerOp, type PickerWorld } from './picker.js';
@@ -209,6 +210,8 @@ export class View {
209210
readonly confirmation = signal<Confirmation | null>(null);
210211
readonly worktreeMenu = signal<WorktreeMenu | null>(null);
211212
readonly addRepo = signal<AddRepoDialog | null>(null);
213+
/** The failed editor launch the editor dialog shows. */
214+
readonly editorFailure = signal<EditorFailure | null>(null);
212215
private readonly drag = signal<Drag | null>(null);
213216
/** The focused pane per tab key, with the tab's panes when it was last resolved; replaced when the user chooses a pane. */
214217
private readonly focusRecords = signal(new Map<string, { termId: number; root: Pane }>());
@@ -355,7 +358,8 @@ export class View {
355358
this.closing.value !== null ||
356359
this.confirmation.value !== null ||
357360
this.addRepo.value !== null ||
358-
this.worktreeMenu.value !== null,
361+
this.worktreeMenu.value !== null ||
362+
this.editorFailure.value !== null,
359363
);
360364

361365
private shownKey = '';

‎test/e2e/editor.spec.ts‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { addWorktree, fakeWorktrees, git, makeRepo } from '../support/daemon-hos
66
import { installRemote } from '../support/fake-ssh.js';
77
import { freePort, type HubHost } from '../support/hub-host.js';
88
import { remoteHub } from '../support/remote-hub.js';
9-
import { byTestId, hubsEntry, repoTab, TID, worktreeEntry } from './contract.js';
9+
import { byTestId, hubsEntry, repoTab, terminalBox, TID, worktreeEntry } from './contract.js';
1010
import {
1111
expect,
12+
LOCAL,
1213
makeRepoWith,
1314
newTerminal,
1415
nodeRemote,
@@ -20,8 +21,11 @@ import {
2021
selectWorktree,
2122
stopHub,
2223
test,
24+
waitScreen,
25+
watcher,
2326
writeHubConfig,
2427
} from './fixture.js';
28+
import { pickerSeen, watchPicker } from './panes.js';
2529
import type { BrowserMessage, HubMessage, WireRecorder } from './wire.js';
2630

2731
const ENABLED_TITLE = 'Open in editor (right-click to change the command)';
@@ -225,6 +229,51 @@ test.describe('open in editor', () => {
225229
await expect(control(page)).toBeEnabled();
226230
});
227231

232+
test('while the failure dialog is open shortcuts act not; once it closes, the terminal takes typed input', async ({ hub, page }) => {
233+
const route = await routeEditor(page);
234+
const { repo } = makeRepoWith(hub, 'app', []);
235+
configure(hub, [repo], null);
236+
await openUi(hub, page);
237+
const term = await newTerminal(page);
238+
await ready(page, term);
239+
await control(page).click();
240+
route.answer({ t: 'error', req: await heldReq(route), host: null, code: 'editor-missing', message: 'kate' });
241+
await expect(dialog(page)).toBeFocused();
242+
243+
await watchPicker(page);
244+
await page.keyboard.press('Control+Shift+KeyT');
245+
await page.waitForTimeout(300); // NOSONAR(S2925) — absence check: nothing to synchronise on
246+
expect(await pickerSeen(page)).toBe(false);
247+
await expect(dialog(page)).toBeFocused();
248+
await page.keyboard.press('Escape');
249+
await expect(dialog(page)).toHaveCount(0);
250+
await page.keyboard.type("echo EDITOR''-CLOSED");
251+
await page.keyboard.press('Enter');
252+
await waitScreen(page, term, 'EDITOR-CLOSED');
253+
});
254+
255+
test('preset choices shown while the failure dialog is open leave it the focus, and take it once it closes', async ({ hub, page }) => {
256+
const route = await routeEditor(page);
257+
const { repo } = makeRepoWith(hub, 'app', []);
258+
configure(hub, [repo], null);
259+
await openUi(hub, page);
260+
const daemon = await watcher(hub, repo);
261+
const term = await daemon.create(repo, { command: 'read -r _; exit 0' });
262+
await expect(page.locator(terminalBox(LOCAL, term.termId))).toBeVisible();
263+
await control(page).click();
264+
route.answer({ t: 'error', req: await heldReq(route), host: null, code: 'editor-missing', message: 'kate' });
265+
await expect(dialog(page)).toBeFocused();
266+
267+
daemon.sendInput(term.termId, '\r');
268+
const options = page.locator(byTestId(TID.presetChoices)).locator(byTestId(TID.presetOption));
269+
await expect(options.nth(0)).toBeVisible();
270+
await page.waitForTimeout(300); // NOSONAR(S2925) — absence check: nothing to synchronise on
271+
await expect(dialog(page)).toBeFocused();
272+
await page.keyboard.press('Escape');
273+
await expect(dialog(page)).toHaveCount(0);
274+
await expect(options.nth(0)).toBeFocused();
275+
});
276+
228277
test('names the first word of the shown command as the missing program', async ({ hub, page }) => {
229278
const route = await routeEditor(page);
230279
const { repo } = makeRepoWith(hub, 'app', []);

0 commit comments

Comments
 (0)