Skip to content

Commit c101b56

Browse files
fix selection and code updates in live
1 parent 4e04d8e commit c101b56

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { Socket } from 'phoenix';
2-
import _debug from '@codesandbox/common/lib/utils/debug';
3-
import uuid from 'uuid';
4-
import { TextOperation } from 'ot';
5-
import { camelizeKeys } from 'humps';
61
import {
7-
Module,
82
Directory,
9-
RoomInfo,
103
LiveMessageEvent,
4+
Module,
5+
RoomInfo,
116
Sandbox,
127
} from '@codesandbox/common/lib/types';
8+
import _debug from '@codesandbox/common/lib/utils/debug';
139
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
14-
import clientsFactory from './clients';
15-
import { transformSandbox } from '../utils/sandbox';
10+
import { camelizeKeys } from 'humps';
11+
import { TextOperation } from 'ot';
12+
import { Socket } from 'phoenix';
13+
import uuid from 'uuid';
14+
1615
import { SandboxAPIResponse } from '../api/types';
16+
import { transformSandbox } from '../utils/sandbox';
17+
import clientsFactory from './clients';
1718

1819
type Options = {
1920
onApplyOperation(args: { moduleShortid: string; operation: any }): void;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class ModelsHandler {
164164
}
165165

166166
const lines = model.getLinesContent() || [];
167-
const activeEditor = this.editorApi.getActiveEditor();
167+
const activeEditor = this.editorApi.getActiveCodeEditor();
168168

169169
userSelections.forEach((data: EditorSelection & UserSelection) => {
170170
const { userId } = data;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export const codeChanged: Action<{
188188
actions.live.onTransformMade({
189189
moduleShortid,
190190
event,
191-
code,
191+
code: state.editor.currentModule.code,
192192
});
193193
} catch (e) {
194194
// Something went wrong while composing the operation, so we're opting for a full sync

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Action, AsyncAction, Operator } from 'app/overmind';
33
import { withLoadApp } from 'app/overmind/factories';
44
import { TextOperation } from 'ot';
55
import { filter, fork, pipe } from 'overmind';
6-
import eventToTransform from '../../utils/event-to-transform';
76

7+
import eventToTransform from '../../utils/event-to-transform';
88
import * as internalActions from './internalActions';
99
import * as liveMessage from './liveMessageOperators';
1010

@@ -22,6 +22,9 @@ export const roomJoined: AsyncAction<{
2222
}
2323

2424
actions.internal.setCurrentSandbox(sandbox);
25+
state.editor.modulesByPath = effects.vscode.fs.create(sandbox);
26+
await effects.vscode.changeSandbox(sandbox);
27+
effects.vscode.openModule(state.editor.currentModule);
2528
state.live.isLoading = false;
2629
});
2730

@@ -123,12 +126,13 @@ export const onCodeReceived: Action = ({ state }) => {
123126
state.live.receivingCode = false;
124127
};
125128

126-
export const onSelectionChanged: Action<{
127-
selection: any;
128-
moduleShortid: string;
129-
}> = ({ state, effects }, { selection, moduleShortid }) => {
129+
export const onSelectionChanged: Action<any> = (
130+
{ state, effects },
131+
selection
132+
) => {
130133
if (state.live.isCurrentEditor) {
131134
const { liveUserId } = state.live;
135+
const moduleShortid = state.editor.currentModuleShortid;
132136
const userIndex = state.live.roomInfo.users.findIndex(
133137
u => u.id === liveUserId
134138
);

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Directory,
33
LiveDisconnectReason,
44
LiveMessage,
5-
LiveMessageEvent,
65
Module,
76
Selection,
87
} from '@codesandbox/common/lib/types';
@@ -190,7 +189,7 @@ export const onModuleDeleted: Operator<
190189
return;
191190
}
192191
// Do not think this really works? Cause this would fork the sandbox
193-
actions.files.removeModule({
192+
actions.files.moduleDeleted({
194193
moduleShortid: data.moduleShortid,
195194
});
196195
});
@@ -234,7 +233,7 @@ export const onDirectoryDeleted: Operator<
234233
}
235234
state.editor.currentModuleShortid = state.editor.mainModule.shortid;
236235
// Again, this does not work very well?
237-
actions.files.removeDirectory({
236+
actions.files.directoryDeleted({
238237
directoryShortid: data.directoryShortid,
239238
});
240239
});
@@ -270,7 +269,7 @@ export const onUserSelection: Operator<
270269
u => u.id === userSelectionLiveUserId
271270
);
272271

273-
effects.vscode.editor.updateUserSelections([
272+
effects.vscode.updateUserSelections([
274273
{
275274
userId: userSelectionLiveUserId,
276275
name: user.username,

0 commit comments

Comments
 (0)