Skip to content

Commit a02679c

Browse files
author
Ives van Hoorne
committed
Fix current module view boilerplates
1 parent 2a5744a commit a02679c

File tree

3 files changed

+90
-95
lines changed

3 files changed

+90
-95
lines changed

src/app/components/sandbox/CodeEditor/Monaco.js

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import FuzzySearch from './FuzzySearch/index';
1919
let modelCache = {};
2020

2121
type State = {
22-
fuzzySearchEnabled: boolean,
22+
fuzzySearchEnabled: boolean
2323
};
2424

2525
type Props = {
@@ -37,7 +37,7 @@ type Props = {
3737
modules: Array<Module>,
3838
directories: Array<Directory>,
3939
dependencies: ?Object,
40-
setCurrentModule: ?(sandboxId: string, moduleId: string) => void,
40+
setCurrentModule: ?(sandboxId: string, moduleId: string) => void
4141
};
4242

4343
const Container = styled.div`
@@ -50,7 +50,7 @@ const fontFamilies = (...families) =>
5050
families
5151
.filter(Boolean)
5252
.map(
53-
family => (family.indexOf(' ') !== -1 ? JSON.stringify(family) : family),
53+
family => (family.indexOf(' ') !== -1 ? JSON.stringify(family) : family)
5454
)
5555
.join(', ');
5656

@@ -128,7 +128,7 @@ const handleError = (
128128
nextErrors: ?Array<ModuleError>,
129129
nextCode: ?string,
130130
prevId: string,
131-
nextId: string,
131+
nextId: string
132132
) => {
133133
if (!monaco) return;
134134
if (nextErrors && nextErrors.length > 0) {
@@ -141,7 +141,7 @@ const handleError = (
141141
startLineNumber: error.line,
142142
endColumn: error.column,
143143
endLineNumber: error.line + 1,
144-
message: error.message,
144+
message: error.message
145145
};
146146
}
147147

@@ -157,7 +157,7 @@ const handleError = (
157157

158158
export default class CodeEditor extends React.PureComponent<Props, State> {
159159
state = {
160-
fuzzySearchEnabled: false,
160+
fuzzySearchEnabled: false
161161
};
162162

163163
syntaxWorker: Worker;
@@ -203,7 +203,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
203203
requestAnimationFrame(() => {
204204
this.monaco.languages.typescript.typescriptDefaults.addExtraLib(
205205
typings,
206-
`file:///${path}`,
206+
`file:///${path}`
207207
);
208208
});
209209
}
@@ -216,26 +216,26 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
216216
classification.startLine,
217217
classification.start,
218218
classification.endLine,
219-
classification.end,
219+
classification.end
220220
),
221221
options: {
222-
inlineClassName: classification.kind,
223-
},
222+
inlineClassName: classification.kind
223+
}
224224
}));
225225

226226
const modelInfo = this.getModelById(this.props.id);
227227

228228
modelInfo.decorations = this.editor.deltaDecorations(
229229
modelInfo.decorations || [],
230-
decorations,
230+
decorations
231231
);
232232
};
233233

234234
updateLintWarnings = (markers: Array<Object>) => {
235235
this.monaco.editor.setModelMarkers(
236236
this.editor.getModel(),
237237
'eslint',
238-
markers,
238+
markers
239239
);
240240
};
241241

@@ -272,7 +272,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
272272
const newModel = this.createModel(
273273
module,
274274
nextProps.modules,
275-
nextProps.directories,
275+
nextProps.directories
276276
);
277277

278278
if (isCurrentlyOpened) {
@@ -330,12 +330,12 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
330330
currentId,
331331
nextId,
332332
nextCode,
333-
nextTitle,
333+
nextTitle
334334
}: {
335335
currentId: string,
336336
nextId: string,
337337
nextCode: ?string,
338-
nextTitle: string,
338+
nextTitle: string
339339
}) => {
340340
if (nextId !== currentId) {
341341
const pos = this.editor.getPosition();
@@ -351,15 +351,15 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
351351
const {
352352
id: currentId,
353353
sandboxId: currentSandboxId,
354-
errors: currentErrors,
354+
errors: currentErrors
355355
} = this.props;
356356

357357
const {
358358
id: nextId,
359359
code: nextCode,
360360
errors: nextErrors,
361361
title: nextTitle,
362-
sandboxId: nextSandboxId,
362+
sandboxId: nextSandboxId
363363
} = nextProps;
364364

365365
if (nextSandboxId !== currentSandboxId) {
@@ -377,7 +377,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
377377
currentId,
378378
nextId,
379379
nextCode,
380-
nextTitle,
380+
nextTitle
381381
}).then(() => {
382382
handleError(
383383
this.monaco,
@@ -386,7 +386,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
386386
nextErrors,
387387
nextCode,
388388
currentId,
389-
nextId,
389+
nextId
390390
);
391391
});
392392
}
@@ -400,11 +400,11 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
400400
const editOperation = {
401401
identifier: {
402402
major: 1,
403-
minor: 1,
403+
minor: 1
404404
},
405405
text: code,
406406
range: new this.monaco.Range(0, 0, lastLine + 1, lastLineColumn),
407-
forceMoveMarkers: false,
407+
forceMoveMarkers: false
408408
};
409409

410410
this.editor.getModel().pushEditOperations([], [editOperation], null);
@@ -446,7 +446,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
446446
this.syntaxWorker.postMessage({
447447
code,
448448
title,
449-
version,
449+
version
450450
});
451451
}
452452
};
@@ -456,7 +456,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
456456
this.lintWorker.postMessage({
457457
code,
458458
title,
459-
version,
459+
version
460460
});
461461
}
462462
};
@@ -467,7 +467,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
467467
this.syntaxHighlight(
468468
newCode,
469469
this.props.title,
470-
this.editor.getModel().getVersionId(),
470+
this.editor.getModel().getVersionId()
471471
);
472472
this.lint(newCode, this.props.title, this.editor.getModel().getVersionId());
473473
};
@@ -479,8 +479,8 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
479479
rules: [
480480
{ token: 'comment', foreground: '626466' },
481481
{ token: 'keyword', foreground: '6CAEDD' },
482-
{ token: 'identifier', foreground: 'fac863' },
483-
],
482+
{ token: 'identifier', foreground: 'fac863' }
483+
]
484484
});
485485
};
486486

@@ -490,7 +490,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
490490

491491
window._cs = {
492492
editor: this.editor,
493-
monaco: this.monaco,
493+
monaco: this.monaco
494494
};
495495

496496
this.setupWorkers();
@@ -506,21 +506,21 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
506506
experimentalDecorators: true,
507507
noEmit: true,
508508
allowJs: true,
509-
typeRoots: ['node_modules/@types'],
509+
typeRoots: ['node_modules/@types']
510510
};
511511

512512
monaco.languages.typescript.typescriptDefaults.setMaximunWorkerIdleTime(-1);
513513
monaco.languages.typescript.javascriptDefaults.setMaximunWorkerIdleTime(-1);
514514
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
515-
compilerDefaults,
515+
compilerDefaults
516516
);
517517
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(
518-
compilerDefaults,
518+
compilerDefaults
519519
);
520520

521521
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
522522
noSemanticValidation: false,
523-
noSyntaxValidation: true,
523+
noSyntaxValidation: true
524524
});
525525

526526
this.initializeModules();
@@ -560,9 +560,9 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
560560
// @param editor The editor instance is passed in as a convinience
561561
run: ed => {
562562
this.setState({
563-
fuzzySearchEnabled: true,
563+
fuzzySearchEnabled: true
564564
});
565-
},
565+
}
566566
});
567567
};
568568

@@ -582,16 +582,20 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
582582
this.monaco.KeyMod.CtrlCmd | this.monaco.KeyCode.KEY_S,
583583
() => {
584584
this.handleSaveCode();
585-
},
585+
}
586586
);
587587
};
588588

589589
disposeModules = () => {
590-
this.editor.setModel(null);
590+
if (this.editor) {
591+
this.editor.setModel(null);
592+
}
591593

592-
this.monaco.editor.getModels().forEach(model => {
593-
model.dispose();
594-
});
594+
if (this.monaco) {
595+
this.monaco.editor.getModels().forEach(model => {
596+
model.dispose();
597+
});
598+
}
595599

596600
modelCache = {};
597601
};
@@ -619,7 +623,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
619623
createModel = (
620624
module: Module,
621625
modules: Array<Module> = this.props.modules,
622-
directories: Array<Directory> = this.props.directories,
626+
directories: Array<Directory> = this.props.directories
623627
) => {
624628
// Remove the first slash, as this will otherwise create errors in monaco
625629
const path = getModulePath(modules, directories, module.id);
@@ -628,15 +632,15 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
628632
const model = this.monaco.editor.createModel(
629633
module.code,
630634
mode === 'javascript' ? 'typescript' : mode,
631-
new this.monaco.Uri().with({ path, scheme: 'file' }),
635+
new this.monaco.Uri().with({ path, scheme: 'file' })
632636
);
633637

634638
model.updateOptions({ tabSize: 2 });
635639

636640
modelCache[module.id] = modelCache[module.id] || {
637641
model: null,
638642
decorations: [],
639-
cursorPos: null,
643+
cursorPos: null
640644
};
641645
modelCache[module.id].model = model;
642646

@@ -666,12 +670,12 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
666670
this.syntaxHighlight(
667671
modelInfo.model.getValue(),
668672
title,
669-
modelInfo.model.getVersionId(),
673+
modelInfo.model.getVersionId()
670674
);
671675
this.lint(
672676
modelInfo.model.getValue(),
673677
title,
674-
modelInfo.model.getVersionId(),
678+
modelInfo.model.getVersionId()
675679
);
676680
});
677681
};
@@ -685,7 +689,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
685689

686690
openReference = data => {
687691
const foundModuleId = Object.keys(modelCache).find(
688-
mId => modelCache[mId].model.uri.path === data.resource.path,
692+
mId => modelCache[mId].model.uri.path === data.resource.path
689693
);
690694

691695
if (foundModuleId) {
@@ -703,7 +707,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
703707
} else {
704708
const pos = {
705709
lineNumber: selection.startLineNumber,
706-
column: selection.startColumn,
710+
column: selection.startColumn
707711
};
708712
this.editor.setPosition(pos);
709713
this.editor.revealPositionInCenter(pos);
@@ -727,7 +731,7 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
727731
code,
728732
mode === 'javascript' ? 'jsx' : mode,
729733
false, // Force false for eslint, since we would otherwise include 2 eslint bundles
730-
preferences.prettierConfig,
734+
preferences.prettierConfig
731735
);
732736

733737
if (newCode !== code) {
@@ -763,11 +767,11 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
763767
// 'monospace',
764768
// ),
765769
minimap: {
766-
enabled: false,
770+
enabled: false
767771
},
768772
ariaLabel: title,
769773
formatOnPaste: true,
770-
lineHeight: (preferences.lineHeight || 1.15) * preferences.fontSize,
774+
lineHeight: (preferences.lineHeight || 1.15) * preferences.fontSize
771775
};
772776
};
773777

@@ -777,16 +781,16 @@ export default class CodeEditor extends React.PureComponent<Props, State> {
777781
modules,
778782
directories,
779783
onlyViewMode,
780-
modulePath,
784+
modulePath
781785
} = this.props;
782786

783787
const options = this.getEditorOptions();
784788

785789
const requireConfig = {
786790
url: '/public/vs/loader.js',
787791
paths: {
788-
vs: '/public/vs',
789-
},
792+
vs: '/public/vs'
793+
}
790794
};
791795
return (
792796
<Container>

0 commit comments

Comments
 (0)