1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-12 12:40:53 +02:00

Fix showErrors() method of CodeEditor component

- This was causing WebMaker to throw the following error whenever the
showErrors() method was called, preventing the desired behavior of showing
the errors in the CodeMirror gutter:

	Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'instance')
This commit is contained in:
Nick Hogle
2023-10-11 15:26:52 -07:00
parent bf986ce7da
commit 5952919396

View File

@ -187,8 +187,9 @@ export default class CodeEditor extends Component {
showErrors(errors) { showErrors(errors) {
if (this.props.type === 'codemirror') { if (this.props.type === 'codemirror') {
errors.forEach(function(error) { const editor = this.instance;
this.instance.operation(function() { errors.forEach(function (error) {
editor.operation(function () {
var n = document.createElement('div'); var n = document.createElement('div');
n.setAttribute('data-title', error.message); n.setAttribute('data-title', error.message);
n.classList.add('gutter-error-marker'); n.classList.add('gutter-error-marker');
@ -235,11 +236,11 @@ export default class CodeEditor extends Component {
if (!monacoDepsDeferred) { if (!monacoDepsDeferred) {
monacoDepsDeferred = deferred(); monacoDepsDeferred = deferred();
loadCss({ url: 'lib/monaco/monaco.css', id: 'monaco-css' }); loadCss({ url: 'lib/monaco/monaco.css', id: 'monaco-css' });
import(/* webpackChunkName: "monaco" */ '../lib/monaco/monaco.bundle.js').then( import(
() => { /* webpackChunkName: "monaco" */ '../lib/monaco/monaco.bundle.js'
).then(() => {
monacoDepsDeferred.resolve(); monacoDepsDeferred.resolve();
} });
);
} }
return monacoDepsDeferred.promise; return monacoDepsDeferred.promise;
} }
@ -311,23 +312,23 @@ export default class CodeEditor extends Component {
// cursorScrollMargin: '20', has issue with scrolling // cursorScrollMargin: '20', has issue with scrolling
profile: options.profile || '', profile: options.profile || '',
extraKeys: { extraKeys: {
Up: function(editor) { Up: function (editor) {
// Stop up/down keys default behavior when saveditempane is open // Stop up/down keys default behavior when saveditempane is open
// if (isSavedItemsPaneOpen) { // if (isSavedItemsPaneOpen) {
// return; // return;
// } // }
CodeMirror.commands.goLineUp(editor); CodeMirror.commands.goLineUp(editor);
}, },
Down: function(editor) { Down: function (editor) {
// if (isSavedItemsPaneOpen) { // if (isSavedItemsPaneOpen) {
// return; // return;
// } // }
CodeMirror.commands.goLineDown(editor); CodeMirror.commands.goLineDown(editor);
}, },
'Shift-Tab': function(editor) { 'Shift-Tab': function (editor) {
CodeMirror.commands.indentAuto(editor); CodeMirror.commands.indentAuto(editor);
}, },
'Shift-Ctrl-F': function(editor) { 'Shift-Ctrl-F': function (editor) {
if (options.prettier) { if (options.prettier) {
prettify({ prettify({
content: editor.getValue(), content: editor.getValue(),
@ -336,7 +337,7 @@ export default class CodeEditor extends Component {
} }
trackEvent('ui', 'prettifyKeyboardShortcut'); trackEvent('ui', 'prettifyKeyboardShortcut');
}, },
Tab: function(editor) { Tab: function (editor) {
if (options.emmet) { if (options.emmet) {
const didEmmetWork = editor.execCommand( const didEmmetWork = editor.execCommand(
'emmetExpandAbbreviation' 'emmetExpandAbbreviation'