Skip to content

Commit 14673be

Browse files
committed
add comments
1 parent fed009c commit 14673be

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apps/vscode/src/providers/editor/editor.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,22 @@ export class VisualEditorProvider implements CustomTextEditorProvider {
164164
this.editorPendingSwitchToVisual.delete(uri.toString());
165165
}
166166

167+
// The `tab` we get from the change event is not precisely the same
168+
// as the tab in `window.tabGroups`, so if we try and close `tab` we
169+
// get a "tab not found" error. The one we care about does exist, but we have
170+
// manually find it via URI, which is a stable field to match on.
167171
if (editorMode && editorMode != viewType && !isSwitch) {
168172
const allTabs = window.tabGroups.all.flatMap(group => group.tabs);
169173

170174
// find tab to close if swapping editor type
171-
const tabsToClose = allTabs.filter(tab =>
175+
const tabToClose = allTabs.find(tab =>
172176
((tab.input instanceof TabInputText) || (tab.input instanceof TabInputCustom)) &&
173177
(tab.input?.uri?.toString() === uri?.toString())
174178
);
175-
176-
await window.tabGroups.close(tabsToClose, true);
179+
if (!tabToClose) {
180+
return;
181+
}
182+
await window.tabGroups.close(tabToClose, true);
177183
await commands.executeCommand("vscode.openWith", uri, editorMode);
178184
return;
179185
}

0 commit comments

Comments
 (0)