Skip to content

Commit fcdc5c5

Browse files
authored
Fix CodeSandbox Live between Linux and Windows (codesandbox#990)
* Fix CodeSandbox Live between Linux and Windows * Come on CircleCI! * Don't send double line breaks from windows * Devbuild * Devbuild * Revert "Devbuild" This reverts commit edbd7c5.
1 parent 30a2db6 commit fcdc5c5

File tree

1 file changed

+18
-11
lines changed
  • packages/app/src/app/components/CodeEditor/Monaco

1 file changed

+18
-11
lines changed

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,9 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
477477
}
478478

479479
if (change.text) {
480-
otOperation.insert(change.text);
481-
delta += change.text.length;
480+
const normalizedChangeText = change.text.split(/\r?\n/).join('\n');
481+
otOperation.insert(normalizedChangeText);
482+
delta += normalizedChangeText.length;
482483
}
483484
}
484485

@@ -956,12 +957,15 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
956957
triggerCharacters: ['"', "'", '.'],
957958
provideCompletionItems: (model, position) => {
958959
// Get editor content before the pointer
959-
const textUntilPosition = model.getValueInRange({
960-
startLineNumber: 1,
961-
startColumn: 1,
962-
endLineNumber: position.lineNumber,
963-
endColumn: position.column,
964-
});
960+
const textUntilPosition = model.getValueInRange(
961+
{
962+
startLineNumber: 1,
963+
startColumn: 1,
964+
endLineNumber: position.lineNumber,
965+
endColumn: position.column,
966+
},
967+
1
968+
);
965969

966970
if (
967971
/(([\s|\n]from\s)|(\brequire\b\())["|']\.*$/.test(textUntilPosition)
@@ -1246,7 +1250,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
12461250
};
12471251

12481252
handleChange = () => {
1249-
const newCode = this.editor.getModel().getValue() || '';
1253+
const newCode = this.editor.getModel().getValue(1) || '';
12501254
const currentModule = this.currentModule;
12511255
const title = currentModule.title;
12521256

@@ -1504,7 +1508,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
15041508
}
15051509

15061510
this.lint(
1507-
modelInfo.model.getValue(),
1511+
modelInfo.model.getValue(1),
15081512
title,
15091513
modelInfo.model.getVersionId()
15101514
);
@@ -1554,7 +1558,10 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
15541558
});
15551559
};
15561560

1557-
getCode = () => this.editor.getValue();
1561+
getCode = () =>
1562+
this.editor.getValue({
1563+
lineEnding: '\n',
1564+
});
15581565

15591566
handleSaveCode = async () => {
15601567
const onSave = this.props.onSave;

0 commit comments

Comments
 (0)