diff --git a/src/editors/sharedComponents/CodeEditor/hooks.js b/src/editors/sharedComponents/CodeEditor/hooks.js index 376edff00..e0cf43b6b 100644 --- a/src/editors/sharedComponents/CodeEditor/hooks.js +++ b/src/editors/sharedComponents/CodeEditor/hooks.js @@ -30,7 +30,7 @@ export const cleanHTML = ({ initialText }) => { export const syntaxChecker = ({ textArr, lang }) => { const diagnostics = []; - if (lang === 'xml') { + if (lang === 'xml' && textArr) { const docString = textArr.join('\n'); const xmlDoc = ` ${docString}`; @@ -70,7 +70,7 @@ export const createCodeMirrorDomNode = ({ languageExtension, EditorView.lineWrapping, linter((view) => { - const textArr = view.docView.view.viewState.state.doc.text; + const textArr = view.state.doc.text; return syntaxChecker({ textArr, lang }); }), ], diff --git a/src/editors/sharedComponents/CodeEditor/index.test.jsx b/src/editors/sharedComponents/CodeEditor/index.test.jsx index 9f7d7c94e..26e935299 100644 --- a/src/editors/sharedComponents/CodeEditor/index.test.jsx +++ b/src/editors/sharedComponents/CodeEditor/index.test.jsx @@ -123,6 +123,13 @@ describe('CodeEditor', () => { expect(diagnostics).toEqual([]); }); }); + describe('textArr is undefined', () => { + it('returns empty array', () => { + let textArr; + const diagnostics = hooks.syntaxChecker({ textArr, lang: 'html' }); + expect(diagnostics).toEqual([]); + }); + }); describe('lang equals xml', () => { it('returns empty array', () => { const textArr = ['', '

', 'this is some text', '

', '
'];