From 765dbf71b73b463123b7dbcfde50bacca9c00d95 Mon Sep 17 00:00:00 2001 From: danny Date: Sat, 31 Oct 2026 14:54:22 +0100 Subject: [PATCH] A3: vcs.toggleBlame without a path waits for tabs just opened Over the control channel, a toggle right after file.open ran before the new tab was adopted (bufferOpened fetches the buffer first), so it found no active tab. The editor store now exposes settled() for adoptions in flight. Co-Authored-By: Claude Opus 5.5 --- ui/src/components/layout/MainLayout.vue | 8 ++++++-- ui/src/stores/editor.ts | 20 ++++++++++++++++++-- ui/tests/vcs/Log.test.ts | 7 +++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ui/src/components/layout/MainLayout.vue b/ui/src/components/layout/MainLayout.vue index 7a19b3d..1e8f5ac 100644 --- a/ui/src/components/layout/MainLayout.vue +++ b/ui/src/components/layout/MainLayout.vue @@ -35,7 +35,8 @@ * path, of the active editor tab's file); neither has a default shortcut. * `vcs.showCommit {hash}` (M4.7) shows the Log with that commit selected * (a click on a blame annotation); `vcs.toggleBlame {path?}` shows or - * hides the blame annotations of a file (default: the active tab's). No + * hides the blame annotations of a file (default: the active tab's, once + * tabs for buffers just opened are adopted). No * default shortcuts. * * A slim header bar along the top (M3.9) holds the app menu @@ -248,8 +249,11 @@ onMounted(() => { enabled: () => project.root !== null, }), commands.provide(TOGGLE_BLAME_COMMAND, { - run: (params) => { + run: async (params) => { const given = (params as { path?: unknown } | null)?.path; + if (typeof given !== "string" || given === "") { + await editor.settled(); + } const path = typeof given === "string" && given !== "" ? given : editor.activeTab?.path; if (path !== undefined) { toggleBlame(path); diff --git a/ui/src/stores/editor.ts b/ui/src/stores/editor.ts index a37d3af..b246609 100644 --- a/ui/src/stores/editor.ts +++ b/ui/src/stores/editor.ts @@ -423,6 +423,9 @@ export const useEditorStore = defineStore("editor", () => { closePrompt.value = null; } + /** Adoptions of `bufferOpened` buffers still fetching their state. */ + const adopting = new Set>(); + /** * Adds a tab for a buffer opened elsewhere (control channel, replay after * a reload), fetching its text first. When several open at once, the @@ -445,6 +448,15 @@ export const useEditorStore = defineStore("editor", () => { } } + /** + * Waits until the tabs of buffers opened so far are adopted, so a + * command right after `file.open` (over the control channel) sees the + * new tab as the active one. + */ + async function settled(): Promise { + await Promise.all([...adopting]); + } + /** * Activates the tab of a buffer that `file.open` found already open * (`bufferFocused`). It also outranks adoptions still fetching, so the @@ -468,9 +480,12 @@ export const useEditorStore = defineStore("editor", () => { case "projectClosed": clear(); break; - case "bufferOpened": - void adoptOpened(event.id); + case "bufferOpened": { + const adoption = adoptOpened(event.id); + adopting.add(adoption); + void adoption.finally(() => adopting.delete(adoption)); break; + } case "bufferFocused": focusOpened(event.id); break; @@ -523,6 +538,7 @@ export const useEditorStore = defineStore("editor", () => { tabs, activeId, activeTab, + settled, closePrompt, lastError, lastOpen, diff --git a/ui/tests/vcs/Log.test.ts b/ui/tests/vcs/Log.test.ts index 0a68b8d..5f63859 100644 --- a/ui/tests/vcs/Log.test.ts +++ b/ui/tests/vcs/Log.test.ts @@ -37,6 +37,7 @@ import { useLogStore, } from "../../src/components/vcs/log/log"; import LogToolWindow from "../../src/components/vcs/log/LogToolWindow.vue"; +import { useEditorStore } from "../../src/stores/editor"; import { useNotificationsStore } from "../../src/stores/notifications"; import { useProjectStore } from "../../src/stores/project"; @@ -139,6 +140,8 @@ function execute(command: string, p: Record): Promise truncated: false, }); } + case "buffer.get": + return Promise.resolve({ id: p.id, path: "src/opened.php", text: " { expect(isBlameShown("src/a.php")).toBe(true); await commands.execute(TOGGLE_BLAME_COMMAND, { path: "src/a.php" }); expect(isBlameShown("src/a.php")).toBe(false); + + useEditorStore(pinia).handleEvent({ kind: "bufferOpened", id: 5 }); + await commands.execute(TOGGLE_BLAME_COMMAND, {}); + expect(isBlameShown("src/opened.php")).toBe(true); }); });