Skip to content

Commit f8df5c1

Browse files
committed
Fix opening files with different carriage returns
We compared the code of prev/next module by a simple ===, which didn't work if the carriage returns were different. We now normalize the carriage returns before comparing. Fixes codesandbox#726
1 parent 7e03c8e commit f8df5c1

File tree

1 file changed

+9
-5
lines changed
  • packages/app/src/app/components/CodeEditor/Monaco

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
371371
suppressImplicitAnyIndexErrors:
372372
hasNativeTypescript && existingConfig.suppressImplicitAnyIndexErrors,
373373
noUnusedLocals: hasNativeTypescript && existingConfig.noUnusedLocals,
374+
375+
newLine: this.monaco.languages.typescript.NewLineKind.LineFeed,
374376
};
375377

376378
this.monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
@@ -1180,10 +1182,13 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
11801182
const currentModule = this.currentModule;
11811183
const title = currentModule.title;
11821184

1183-
if (
1184-
currentModule.code !== newCode &&
1185-
!(currentModule.code === null && newCode === '')
1186-
) {
1185+
const codeEquals =
1186+
(currentModule.code == null && newCode === '') ||
1187+
(currentModule.code != null &&
1188+
currentModule.code.replace(/\r\n/g, '\n') ===
1189+
newCode.replace(/\r\n/g, '\n'));
1190+
1191+
if (!codeEquals) {
11871192
if (this.props.onChange) {
11881193
this.props.onChange(newCode);
11891194
}
@@ -1494,7 +1499,6 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
14941499
folding: true,
14951500
glyphMargin: false,
14961501
fixedOverflowWidgets: true,
1497-
14981502
readOnly: !!this.props.readOnly,
14991503
};
15001504
};

0 commit comments

Comments
 (0)