@@ -24,7 +24,7 @@ import { RemixCodeActionProvider } from './providers/codeActionProvider'
24
24
import './remix-ui-editor.css'
25
25
import { circomLanguageConfig , circomTokensProvider } from './syntaxes/circom'
26
26
import { noirLanguageConfig , noirTokensProvider } from './syntaxes/noir'
27
- import { IPosition } from 'monaco-editor'
27
+ import { IPosition , IRange } from 'monaco-editor'
28
28
import { RemixInLineCompletionProvider } from './providers/inlineCompletionProvider'
29
29
const _paq = ( window . _paq = window . _paq || [ ] )
30
30
@@ -159,8 +159,8 @@ export const EditorUI = (props: EditorUIProps) => {
159
159
const [ isSplit , setIsSplit ] = useState ( true )
160
160
const [ isDiff , setIsDiff ] = useState ( props . isDiff || false )
161
161
const [ currentDiffFile , setCurrentDiffFile ] = useState ( props . currentDiffFile || '' )
162
- const [ isPromptSuggestion , setIsPromptSuggestion ] = useState ( false )
163
- const [ decoratorListCollection , setDecoratorListCollection ] = useState < Record < string , any > > ( { } )
162
+ const [ decoratorListCollection , setDecoratorListCollection ] = useState < Record < string , monacoTypes . editor . IEditorDecorationsCollection > > ( { } )
163
+ const [ disposedWidgets , setDisposedWidgets ] = useState < Record < string , Record < string , monacoTypes . IRange [ ] > > > ( { } )
164
164
const defaultEditorValue = `
165
165
\t\t\t\t\t\t\t ____ _____ __ __ ___ __ __ ___ ____ _____
166
166
\t\t\t\t\t\t\t| _ \\ | ____| | \\/ | |_ _| \\ \\/ / |_ _| | _ \\ | ____|
@@ -344,6 +344,72 @@ export const EditorUI = (props: EditorUIProps) => {
344
344
defineAndSetTheme ( monacoRef . current )
345
345
} )
346
346
347
+ useEffect ( ( ) => {
348
+ if ( decoratorListCollection && currentFileRef . current && ( props . currentFile === currentFileRef . current ) ) {
349
+ const widgetsToDispose = { }
350
+ Object . keys ( decoratorListCollection ) . forEach ( ( widgetId ) => {
351
+ const ranges = decoratorListCollection [ widgetId ] . getRanges ( )
352
+
353
+ widgetsToDispose [ widgetId ] = ranges
354
+ } )
355
+ setDisposedWidgets ( { ...disposedWidgets , [ currentFileRef . current ] : widgetsToDispose } )
356
+ }
357
+ } , [ decoratorListCollection ] )
358
+
359
+ useEffect ( ( ) => {
360
+ if ( currentFileRef . current ) {
361
+ if ( props . currentFile !== currentFileRef . current ) {
362
+ const restoredWidgets = disposedWidgets [ props . currentFile ]
363
+ if ( restoredWidgets ) {
364
+ Object . keys ( restoredWidgets ) . forEach ( ( widgetId ) => {
365
+ const ranges = restoredWidgets [ widgetId ]
366
+ let decoratorList : monacoTypes . editor . IEditorDecorationsCollection
367
+
368
+ if ( ranges . length === 1 ) {
369
+ decoratorList = editorRef . current . createDecorationsCollection ( [ {
370
+ range : ranges [ 0 ] ,
371
+ options : {
372
+ isWholeLine : true ,
373
+ className : 'newChangesDecoration' ,
374
+ marginClassName : 'newChangesDecoration' ,
375
+ }
376
+ } ] )
377
+ } else {
378
+ decoratorList = editorRef . current . createDecorationsCollection ( [ {
379
+ range : ranges [ 0 ] ,
380
+ options : {
381
+ isWholeLine : true ,
382
+ className : 'newChangesDecoration' ,
383
+ marginClassName : 'newChangesDecoration' ,
384
+ }
385
+ } , {
386
+ range : ranges [ 1 ] ,
387
+ options : {
388
+ isWholeLine : true ,
389
+ className : 'modifiedChangesDecoration' ,
390
+ marginClassName : 'modifiedChangesDecoration' ,
391
+ }
392
+ } ] )
393
+ }
394
+ setTimeout ( ( ) => {
395
+ const newEntryRange = decoratorList . getRange ( 0 )
396
+
397
+ addAcceptDeclineWidget ( widgetId , editorRef . current , { column : 0 , lineNumber : newEntryRange . startLineNumber + 1 } , ( ) => acceptHandler ( decoratorList , widgetId ) , ( ) => rejectHandler ( decoratorList , widgetId ) )
398
+ } , 150 )
399
+ } )
400
+ setCurrentDiffFile ( props . currentFile + '-ai' )
401
+ }
402
+ if ( disposedWidgets [ currentFileRef . current ] ) {
403
+ Object . keys ( disposedWidgets [ currentFileRef . current ] ) . forEach ( ( widgetId ) => {
404
+ editorRef . current . removeContentWidget ( {
405
+ getId : ( ) => widgetId
406
+ } )
407
+ } )
408
+ }
409
+ }
410
+ }
411
+ } , [ props . currentFile ] )
412
+
347
413
useEffect ( ( ) => {
348
414
if ( ! ( editorRef . current || diffEditorRef . current ) || ! props . currentFile ) return
349
415
currentFileRef . current = props . currentFile
0 commit comments