@@ -32,13 +32,16 @@ import { FolderIcon } from '../../../../common/icons';
3232import { IconButton } from '../../../../common/IconButton' ;
3333
3434import useCodeMirror from './codemirror' ;
35- import { useEffectWithComparison } from '../../hooks/custom-hooks' ;
35+
36+ import {
37+ addErrorDecoration ,
38+ removeErrorDecorations
39+ } from './consoleErrorDecoration' ;
3640
3741function Editor ( {
3842 provideController,
3943 files,
4044 file,
41- theme,
4245 linewrap,
4346 lineNumbers,
4447 closeProjectOptions,
@@ -57,8 +60,6 @@ function Editor({
5760 autocloseBracketsQuotes,
5861 fontSize,
5962 consoleEvents,
60- hideRuntimeErrorWarning,
61- runtimeErrorWarningVisible,
6263 expandConsole,
6364 isExpanded,
6465 t,
@@ -85,17 +86,15 @@ function Editor({
8586 const {
8687 setupCodeMirrorOnContainerMounted,
8788 teardownCodeMirror,
88- // cmInstance ,
89+ codemirrorView ,
8990 getContent,
9091 tidyCode,
9192 showSearch
9293 } = useCodeMirror ( {
93- theme,
9494 lineNumbers,
9595 linewrap,
9696 autocloseBracketsQuotes,
9797 setUnsavedChanges,
98- hideRuntimeErrorWarning,
9998 updateFileContent,
10099 file,
101100 files,
@@ -132,54 +131,32 @@ function Editor({
132131 } ;
133132 } , [ ] ) ;
134133
135- // Updates the error console.
136- // TODO: Need to revisit this functionality for v6.
137- useEffectWithComparison (
138- ( _ , prevProps ) => {
139- if ( runtimeErrorWarningVisible ) {
140- if (
141- prevProps . consoleEvents &&
142- consoleEvents . length !== prevProps . consoleEvents . length
143- ) {
144- consoleEvents . forEach ( ( consoleEvent ) => {
145- if ( consoleEvent . method === 'error' ) {
146- // It doesn't work if you create a new Error, but this works
147- // LOL
148- const errorObj = { stack : consoleEvent . data [ 0 ] . toString ( ) } ;
149- StackTrace . fromError ( errorObj ) . then ( ( stackLines ) => {
150- expandConsole ( ) ;
151- const line = stackLines . find (
152- ( l ) => l . fileName && l . fileName . startsWith ( '/' )
153- ) ;
154- if ( ! line ) return ;
155- const fileNameArray = line . fileName . split ( '/' ) ;
156- const fileName = fileNameArray . slice ( - 1 ) [ 0 ] ;
157- const filePath = fileNameArray . slice ( 0 , - 1 ) . join ( '/' ) ;
158- const fileWithError = files . find (
159- ( f ) => f . name === fileName && f . filePath === filePath
160- ) ;
161- setSelectedFile ( fileWithError . id ) ;
162- // cmInstance.current.addLineClass(
163- // line.lineNumber - 1,
164- // 'background',
165- // 'line-runtime-error'
166- // );
167- } ) ;
168- }
169- } ) ;
170- } else {
171- // for (let i = 0; i < cmInstance.current.lineCount(); i += 1) {
172- // cmInstance.current.removeLineClass(
173- // i,
174- // 'background',
175- // 'line-runtime-error'
176- // );
177- // }
178- }
179- }
180- } ,
181- [ consoleEvents , runtimeErrorWarningVisible ]
182- ) ;
134+ // Updates the runtime error console.
135+ useEffect ( ( ) => {
136+ const consoleErrors = consoleEvents . filter ( ( e ) => e . method === 'error' ) ;
137+
138+ if ( consoleErrors . length > 0 ) {
139+ const firstError = consoleErrors [ 0 ] ;
140+ const errorObj = { stack : firstError . data [ 0 ] . toString ( ) } ;
141+ StackTrace . fromError ( errorObj ) . then ( ( stackLines ) => {
142+ expandConsole ( ) ;
143+ const line = stackLines . find (
144+ ( l ) => l . fileName && l . fileName . startsWith ( '/' )
145+ ) ;
146+ if ( ! line ) return ;
147+ const fileNameArray = line . fileName . split ( '/' ) ;
148+ const fileName = fileNameArray . slice ( - 1 ) [ 0 ] ;
149+ const filePath = fileNameArray . slice ( 0 , - 1 ) . join ( '/' ) ;
150+ const fileWithError = files . find (
151+ ( f ) => f . name === fileName && f . filePath === filePath
152+ ) ;
153+ setSelectedFile ( fileWithError . id ) ;
154+ addErrorDecoration ( codemirrorView . current , line . lineNumber ) ;
155+ } ) ;
156+ } else {
157+ removeErrorDecorations ( codemirrorView . current ) ;
158+ }
159+ } , [ consoleEvents ] ) ;
183160
184161 const editorSectionClass = classNames ( {
185162 editor : true ,
@@ -291,7 +268,6 @@ Editor.propTypes = {
291268 startSketch : PropTypes . func . isRequired ,
292269 autorefresh : PropTypes . bool . isRequired ,
293270 isPlaying : PropTypes . bool . isRequired ,
294- theme : PropTypes . string . isRequired ,
295271 files : PropTypes . arrayOf (
296272 PropTypes . shape ( {
297273 id : PropTypes . string . isRequired ,
@@ -304,8 +280,6 @@ Editor.propTypes = {
304280 closeProjectOptions : PropTypes . func . isRequired ,
305281 expandSidebar : PropTypes . func . isRequired ,
306282 clearConsole : PropTypes . func . isRequired ,
307- hideRuntimeErrorWarning : PropTypes . func . isRequired ,
308- runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
309283 provideController : PropTypes . func . isRequired ,
310284 t : PropTypes . func . isRequired ,
311285 setSelectedFile : PropTypes . func . isRequired ,
0 commit comments