Skip to content

Commit 3832646

Browse files
Fix issue with revert module
1 parent 0b3d2e9 commit 3832646

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { TextOperation } from 'ot';
1111
import { Socket } from 'phoenix';
1212
import uuid from 'uuid';
1313

14-
import eventToTransform from '../../utils/event-to-transform';
1514
import { SandboxAPIResponse } from '../api/types';
1615
import { transformSandbox } from '../utils/sandbox';
1716
import clientsFactory from './clients';
@@ -184,9 +183,7 @@ export default {
184183
module: directory,
185184
});
186185
},
187-
sendCodeUpdate(moduleShortid: string, currentCode: string, event: any) {
188-
const { operation } = eventToTransform(event, currentCode);
189-
186+
sendCodeUpdate(moduleShortid: string, operation: any) {
190187
if (!operation) {
191188
return;
192189
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ export class ModelsHandler {
9393
return null;
9494
}
9595

96+
public async revertModule(module: Module) {
97+
const fileModel = this.editorApi.textFileService
98+
.getFileModels()
99+
.find(
100+
fileModelItem =>
101+
fileModelItem.resource.path === '/sandbox' + module.path
102+
);
103+
104+
fileModel.revert();
105+
}
106+
96107
public changeModule = async (module: Module) => {
97108
const moduleModel = this.getModuleModel(module);
98109

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export class VSCodeEffect {
205205
}
206206
}
207207

208+
public revertModule(module: Module) {
209+
this.modelsHandler.revertModule(module);
210+
}
211+
208212
public async applyOperation(
209213
moduleShortid: string,
210214
operation: (string | number)[]

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ModuleTab,
88
WindowOrientation,
99
} from '@codesandbox/common/lib/types';
10+
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
1011
import { Action, AsyncAction } from 'app/overmind';
1112
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
1213
import {
@@ -17,6 +18,7 @@ import {
1718
import { clearCorrectionsFromAction } from 'app/utils/corrections';
1819
import { json } from 'overmind';
1920

21+
import eventToTransform from '../../utils/event-to-transform';
2022
import * as internalActions from './internalActions';
2123

2224
export const internal = internalActions;
@@ -198,7 +200,11 @@ export const codeChanged: Action<{
198200
}
199201

200202
if (state.live.isLive) {
201-
effects.live.sendCodeUpdate(moduleShortid, module.code, event);
203+
const operation = event
204+
? eventToTransform(event, module.code).operation
205+
: getTextOperation(module.code, code);
206+
207+
effects.live.sendCodeUpdate(moduleShortid, operation);
202208
}
203209

204210
actions.editor.internal.setModuleCode({
@@ -493,6 +499,8 @@ export const discardModuleChanges: Action<{
493499

494500
module.updatedAt = new Date().toString();
495501

502+
effects.vscode.revertModule(module);
503+
496504
state.editor.changedModuleShortids.splice(
497505
state.editor.changedModuleShortids.indexOf(moduleShortid),
498506
1

packages/app/src/sandbox/status-screen/overlay-manager.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ export function resetOverlay() {
99
const delay = Date.now() - iframeRenderedAt > 1000 ? 0 : 1000;
1010

1111
setTimeout(() => {
12-
if (iframeReference) {
13-
iframeReference.style.opacity = '0';
14-
setTimeout(() => {
15-
if (iframeReference) {
16-
document.body.removeChild(iframeReference);
17-
}
18-
}, 500);
19-
}
12+
iframeReference.style.opacity = '0';
13+
setTimeout(() => {
14+
if (iframeReference.parentNode) {
15+
document.body.removeChild(iframeReference);
16+
}
17+
}, 500);
2018
}, delay);
2119
} catch (e) {
2220
/* nothing */

0 commit comments

Comments
 (0)