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:
parent
c3acd9f60a
commit
765dbf71b7
3 changed files with 31 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue