Skip to content

Commit ad436b4

Browse files
fix forking
1 parent 2067b84 commit ad436b4

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export class VSCodeEffect {
432432
{ IEditorService },
433433
{ ICodeEditorService },
434434
{ ITextFileService },
435+
435436
{ IEditorGroupsService },
436437
{ IStatusbarService },
437438
{ IExtensionService },
@@ -446,6 +447,7 @@ export class VSCodeEffect {
446447
r('vs/workbench/services/editor/common/editorService'),
447448
r('vs/editor/browser/services/codeEditorService'),
448449
r('vs/workbench/services/textfile/common/textfiles'),
450+
449451
r('vs/workbench/services/editor/common/editorGroupsService'),
450452
r('vs/platform/statusbar/common/statusbar'),
451453
r('vs/workbench/services/extensions/common/extensions'),
@@ -491,6 +493,7 @@ export class VSCodeEffect {
491493

492494
this.commandService.resolve(commandService);
493495
this.extensionService.resolve(extensionService);
496+
494497
this.extensionEnablementService.resolve(extensionEnablementService);
495498

496499
const editorPart = accessor.get(IEditorGroupsService);

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,18 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
7777

7878
newId = actions.editor.internal.ensureSandboxId(newId);
7979

80-
if (state.live.isLive) {
81-
actions.live.internal.disconnect();
80+
// This happens when we fork. This can be avoided with state first routing
81+
if (state.editor.currentId === newId) {
82+
return;
8283
}
8384

84-
if (state.editor.sandboxes[newId] && !state.editor.sandboxes[newId].team) {
85-
const sandbox = await effects.api.getSandbox(newId);
86-
87-
actions.internal.updateCurrentSandbox(sandbox);
88-
state.editor.currentId = newId;
89-
state.editor.isLoading = false;
90-
91-
await actions.editor.internal.initializeLiveSandbox(sandbox);
85+
const hasExistingSandbox = Boolean(state.editor.currentId);
9286

93-
return;
87+
if (state.live.isLive) {
88+
actions.live.internal.disconnect();
9489
}
9590

96-
state.editor.isLoading = !state.editor.currentId;
91+
state.editor.isLoading = !hasExistingSandbox;
9792
state.editor.notFound = false;
9893

9994
// Only reset changed modules if sandbox wasn't in memory, otherwise a fork
@@ -103,12 +98,9 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
10398
try {
10499
const sandbox = await effects.api.getSandbox(newId);
105100

106-
if (state.editor.sandboxes[newId]) {
107-
actions.internal.updateCurrentSandbox(sandbox);
108-
} else {
109-
await effects.vscode.closeAllTabs();
110-
actions.internal.setCurrentSandbox(sandbox);
111-
}
101+
await effects.vscode.closeAllTabs();
102+
103+
actions.internal.setCurrentSandbox(sandbox);
112104

113105
state.editor.modulesByPath = effects.vscode.fs.create(sandbox);
114106
} catch (error) {

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ export const forkSandbox: AsyncAction<{
298298

299299
await actions.internal.setCurrentSandbox(forkedSandbox);
300300
state.editor.modulesByPath = effects.vscode.fs.create(forkedSandbox);
301+
await effects.vscode.changeSandbox(forkedSandbox);
302+
effects.vscode.openModule(state.editor.currentModule);
301303
effects.notificationToast.success('Forked sandbox!');
302304
effects.router.updateSandboxUrl(forkedSandbox);
303305
} catch (error) {

0 commit comments

Comments
 (0)