@@ -208,7 +208,7 @@ const AutoSuggestion = ({
208208 const suggestionRequestData = React . useRef < RequestMetaData > ( { requestId : undefined } ) ;
209209 const [ pathValidationPending , setPathValidationPending ] = React . useState ( false ) ;
210210 const validationRequestData = React . useRef < RequestMetaData > ( { requestId : undefined } ) ;
211- const [ , setErrorMarkers ] = React . useState < any [ ] > ( [ ] ) ;
211+ const errorMarkers = React . useRef < any [ ] > ( [ ] )
212212 const [ validationResponse , setValidationResponse ] = useState < CodeAutocompleteFieldValidationResult | undefined > (
213213 undefined
214214 ) ;
@@ -288,7 +288,6 @@ const AutoSuggestion = ({
288288 return ( ) => removeMarkFromText ( { view : cm , from, to } ) ;
289289 }
290290 } else {
291- //remove redundant markers
292291 if ( cm ) {
293292 removeMarkFromText ( { view : cm , from : 0 , to : cm . state ?. doc . length } ) ;
294293 }
@@ -300,22 +299,27 @@ const AutoSuggestion = ({
300299 React . useEffect ( ( ) => {
301300 const parseError = validationResponse ?. parseError ;
302301 if ( cm ) {
302+ const clearCurrentErrorMarker = ( ) => {
303+ if ( errorMarkers . current . length ) {
304+ const [ from , to ] = errorMarkers . current ;
305+ removeMarkFromText ( { view : cm , from, to } )
306+ errorMarkers . current = [ ]
307+ }
308+ }
303309 if ( parseError ) {
304310 const { message, start, end } = parseError ;
305311 const { toOffset, fromOffset } = getOffsetRange ( cm , start , end ) ;
306- markText ( {
312+ clearCurrentErrorMarker ( )
313+ const { from, to} = markText ( {
307314 view : cm ,
308315 from : fromOffset ,
309316 to : toOffset ,
310317 className : `${ eccgui } -autosuggestion__text--highlighted-error` ,
311318 title : message ,
312319 } ) ;
320+ errorMarkers . current = [ from , to ]
313321 } else {
314- // Valid, clear all error markers
315- setErrorMarkers ( ( previous ) => {
316- previous . forEach ( ( m ) => removeMarkFromText ( { view : cm , from : m . from , to : m . to } ) ) ;
317- return [ ] ;
318- } ) ;
322+ clearCurrentErrorMarker ( )
319323 }
320324 }
321325
0 commit comments