Skip to content
Open
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
26 changes: 23 additions & 3 deletions packages/vscode/src/integrations/editor/tab-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,32 @@ export class TabState implements vscode.Disposable {
*/
private onTabChanged = () => {
// Update the existing signal value instead of creating a new signal
this.activeTabs.value = listOpenTabs(this.workspaceScope.cwd);
this.activeSelection.value = getActiveSelection(this.workspaceScope.cwd);
const newOpenTabs = listOpenTabs(this.workspaceScope.cwd);
this.activeTabs.value = newOpenTabs;

const newSelection = getActiveSelection(this.workspaceScope.cwd);
if (newSelection) {
this.activeSelection.value = newSelection;
} else if (this.activeSelection.value) {
// newSelection is undefined, but there was a previous selection.
// Check if the file for the previous selection is still open.
const lastSelectedFilepath = this.activeSelection.value.filepath;
const isFileStillOpen = newOpenTabs.some(
(tab) => tab.filepath === lastSelectedFilepath,
);
if (!isFileStillOpen) {
// The file was likely closed, so clear the selection.
this.activeSelection.value = undefined;
}
// If the file is still open, we preserve the selection (e.g. when focusing a webview).
}
};

private onSelectionChanged = () => {
this.activeSelection.value = getActiveSelection(this.workspaceScope.cwd);
const newSelection = getActiveSelection(this.workspaceScope.cwd);
if (newSelection !== undefined) {
this.activeSelection.value = newSelection;
}
};

/**
Expand Down