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 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:54:22 +01:00
parent c3acd9f60a
commit 765dbf71b7
3 changed files with 31 additions and 4 deletions

View file

@ -423,6 +423,9 @@ export const useEditorStore = defineStore("editor", () => {
closePrompt.value = null;
}
/** Adoptions of `bufferOpened` buffers still fetching their state. */
const adopting = new Set<Promise<void>>();
/**
* 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<void> {
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,