Skip to content

Commit da92113

Browse files
live fixes
1 parent e3f0fb6 commit da92113

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import {
66
Sandbox,
77
} from '@codesandbox/common/lib/types';
88
import _debug from '@codesandbox/common/lib/utils/debug';
9-
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
109
import { camelizeKeys } from 'humps';
1110
import { TextOperation } from 'ot';
1211
import { Socket } from 'phoenix';
1312
import uuid from 'uuid';
1413

14+
import eventToTransform from '../../utils/event-to-transform';
1515
import { SandboxAPIResponse } from '../api/types';
1616
import { transformSandbox } from '../utils/sandbox';
1717
import clientsFactory from './clients';
@@ -183,12 +183,8 @@ export default {
183183
module: directory,
184184
});
185185
},
186-
sendCodeUpdate(moduleShortid: string, currentCode: string, code: string) {
187-
if (currentCode === code) {
188-
return;
189-
}
190-
191-
const operation = getTextOperation(currentCode, code);
186+
sendCodeUpdate(moduleShortid: string, currentCode: string, event: any) {
187+
const { operation } = eventToTransform(event, currentCode);
192188

193189
if (!operation) {
194190
return;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type OnFileChangeData = {
3030
moduleShortid: string;
3131
title: string;
3232
code: string;
33+
event: any;
3334
model: any;
3435
};
3536

@@ -451,6 +452,7 @@ export class ModelsHandler {
451452
moduleShortid: module.shortid,
452453
title: module.title,
453454
code: model.getValue(),
455+
event: e,
454456
model,
455457
});
456458
} catch (err) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ export const onOperationApplied: Action<{
188188
export const codeChanged: Action<{
189189
moduleShortid: string;
190190
code: string;
191-
}> = ({ effects, state, actions }, { code, moduleShortid }) => {
191+
event?: any;
192+
}> = ({ effects, state, actions }, { code, event, moduleShortid }) => {
192193
effects.analytics.trackOnce('Change Code');
193194

194195
const module = state.editor.currentSandbox.modules.find(
@@ -200,7 +201,7 @@ export const codeChanged: Action<{
200201
}
201202

202203
if (state.live.isLive) {
203-
effects.live.sendCodeUpdate(moduleShortid, module.code, code);
204+
effects.live.sendCodeUpdate(moduleShortid, module.code, event);
204205
}
205206

206207
actions.editor.internal.setModuleCode({

packages/app/src/app/overmind/utils/event-to-transform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TextOperation } from 'ot';
2+
23
import { lineAndColumnToIndex } from './common';
34

45
export default function convertChangeEventToOperation(

0 commit comments

Comments
 (0)