@@ -362,34 +362,8 @@ export const EditorUI = (props: EditorUIProps) => {
362
362
if ( restoredWidgets ) {
363
363
Object . keys ( restoredWidgets ) . forEach ( ( widgetId ) => {
364
364
const ranges = restoredWidgets [ widgetId ]
365
- let decoratorList : monacoTypes . editor . IEditorDecorationsCollection
365
+ const decoratorList = addDecoratorCollection ( widgetId , ranges )
366
366
367
- if ( ranges . length === 1 ) {
368
- decoratorList = editorRef . current . createDecorationsCollection ( [ {
369
- range : ranges [ 0 ] ,
370
- options : {
371
- isWholeLine : true ,
372
- className : 'newChangesDecoration' ,
373
- marginClassName : 'newChangesDecoration' ,
374
- }
375
- } ] )
376
- } else {
377
- decoratorList = editorRef . current . createDecorationsCollection ( [ {
378
- range : ranges [ 0 ] ,
379
- options : {
380
- isWholeLine : true ,
381
- className : 'newChangesDecoration' ,
382
- marginClassName : 'newChangesDecoration' ,
383
- }
384
- } , {
385
- range : ranges [ 1 ] ,
386
- options : {
387
- isWholeLine : true ,
388
- className : 'modifiedChangesDecoration' ,
389
- marginClassName : 'modifiedChangesDecoration' ,
390
- }
391
- } ] )
392
- }
393
367
setTimeout ( ( ) => {
394
368
const newEntryRange = decoratorList . getRange ( 0 )
395
369
@@ -921,30 +895,19 @@ export const EditorUI = (props: EditorUIProps) => {
921
895
const docsRange = await props . plugin . call ( 'codeParser' , "getLineColumnOfNode" , { src : functionNode . documentation . src } )
922
896
const docs = editorRef . current . getModel ( ) . getValueInRange ( new monacoRef . current . Range ( docsRange . start . line , docsRange . start . column , funcRange . start . line , 1000 ) )
923
897
const oldLineCount = ( docs || '' ) . split ( '\n' ) . length - 1
898
+ const ranges = [
899
+ new monacoRef . current . Range ( docsRange . start . line + 1 , 0 , docsRange . start . line + 1 , 0 ) ,
900
+ new monacoRef . current . Range ( docsRange . start . line + newLineCount + 1 , 0 , docsRange . start . line + newLineCount + oldLineCount , 1000 )
901
+ ]
924
902
925
903
editorRef . current . executeEdits ( 'docsChange' , [
926
904
{
927
905
range : new monacoRef . current . Range ( docsRange . start . line + 1 , 0 , docsRange . start . line + 1 , 0 ) ,
928
906
text : outputFunctionComments [ currentFunction . current ] + '\n' ,
929
907
} ,
930
908
] )
931
-
932
- const decoratorList = editorRef . current . createDecorationsCollection ( [ {
933
- range : new monacoRef . current . Range ( docsRange . start . line + 1 , 0 , docsRange . start . line + newLineCount , 1000 ) ,
934
- options : {
935
- isWholeLine : true ,
936
- className : 'newChangesDecoration' ,
937
- marginClassName : 'newChangesDecoration' ,
938
- }
939
- } , {
940
- range : new monacoRef . current . Range ( docsRange . start . line + newLineCount + 1 , 0 , docsRange . start . line + newLineCount + oldLineCount , 1000 ) ,
941
- options : {
942
- isWholeLine : true ,
943
- className : 'modifiedChangesDecoration' ,
944
- marginClassName : 'modifiedChangesDecoration' ,
945
- }
946
- } ] )
947
909
const widgetId = `accept_decline_widget${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) } `
910
+ const decoratorList = addDecoratorCollection ( widgetId , ranges )
948
911
949
912
setCurrentDiffFile ( uri )
950
913
setDecoratorListCollection ( decoratorListCollection => {
@@ -968,15 +931,9 @@ export const EditorUI = (props: EditorUIProps) => {
968
931
text : outputFunctionComments [ currentFunction . current ] + '\n' ,
969
932
} ,
970
933
] )
971
- const decoratorList = editorRef . current . createDecorationsCollection ( [ {
972
- range : new monacoRef . current . Range ( funcRange . start . line + 1 , 0 , funcRange . start . line + newLineCount , 1000 ) ,
973
- options : {
974
- isWholeLine : true ,
975
- className : 'newChangesDecoration' ,
976
- marginClassName : 'newChangesDecoration' ,
977
- }
978
- } ] )
934
+ const ranges = [ new monacoRef . current . Range ( funcRange . start . line + 1 , 0 , funcRange . start . line + newLineCount , 1000 ) ]
979
935
const widgetId = `accept_decline_widget${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) } `
936
+ const decoratorList = addDecoratorCollection ( widgetId , ranges )
980
937
981
938
setCurrentDiffFile ( uri )
982
939
setDecoratorListCollection ( decoratorListCollection => {
@@ -1382,6 +1339,52 @@ export const EditorUI = (props: EditorUIProps) => {
1382
1339
} )
1383
1340
}
1384
1341
1342
+ function addDecoratorCollection ( widgetId : string , ranges : monacoTypes . IRange [ ] ) : monacoTypes . editor . IEditorDecorationsCollection {
1343
+ let decoratorList : monacoTypes . editor . IEditorDecorationsCollection
1344
+ if ( ranges . length === 1 ) {
1345
+ decoratorList = editorRef . current . createDecorationsCollection ( [ {
1346
+ range : ranges [ 0 ] ,
1347
+ options : {
1348
+ isWholeLine : true ,
1349
+ className : 'newChangesDecoration' ,
1350
+ marginClassName : 'newChangesDecoration' ,
1351
+ }
1352
+ } ] )
1353
+ } else {
1354
+ decoratorList = editorRef . current . createDecorationsCollection ( [ {
1355
+ range : ranges [ 0 ] ,
1356
+ options : {
1357
+ isWholeLine : true ,
1358
+ className : 'newChangesDecoration' ,
1359
+ marginClassName : 'newChangesDecoration' ,
1360
+ }
1361
+ } , {
1362
+ range : ranges [ 1 ] ,
1363
+ options : {
1364
+ isWholeLine : true ,
1365
+ className : 'modifiedChangesDecoration' ,
1366
+ marginClassName : 'modifiedChangesDecoration' ,
1367
+ }
1368
+ } ] )
1369
+ }
1370
+
1371
+ decoratorList . onDidChange ( ( ) => {
1372
+ const newRanges = decoratorList . getRanges ( )
1373
+
1374
+ if ( newRanges . length === 0 ) return
1375
+ if ( newRanges [ 0 ] . startLineNumber !== ranges [ 0 ] . startLineNumber && document . getElementById ( widgetId ) ) {
1376
+ editorRef . current . removeContentWidget ( {
1377
+ getId : ( ) => widgetId
1378
+ } )
1379
+
1380
+ addAcceptDeclineWidget ( widgetId , editorRef . current , { column : 0 , lineNumber : newRanges [ 0 ] . startLineNumber + 1 } , ( ) => acceptHandler ( decoratorList , widgetId ) , ( ) => rejectHandler ( decoratorList , widgetId ) )
1381
+ }
1382
+ ranges = newRanges
1383
+ } )
1384
+
1385
+ return decoratorList
1386
+ }
1387
+
1385
1388
function showCustomDiff ( uri : string ) {
1386
1389
const lineChanges : monacoTypes . editor . ILineChange [ ] = diffEditorRef . current . getLineChanges ( )
1387
1390
let totalLineDifference = 0
@@ -1402,22 +1405,12 @@ export const EditorUI = (props: EditorUIProps) => {
1402
1405
} ,
1403
1406
] )
1404
1407
1405
- const decoratorList = editorRef . current . createDecorationsCollection ( [ {
1406
- range : new monacoRef . current . Range ( modifiedStartLine , 0 , modifiedEndLine , 1000 ) ,
1407
- options : {
1408
- isWholeLine : true ,
1409
- className : 'newChangesDecoration' ,
1410
- marginClassName : 'newChangesDecoration' ,
1411
- }
1412
- } , {
1413
- range : new monacoRef . current . Range ( originalStartLine , 0 , originalEndLine , 1000 ) ,
1414
- options : {
1415
- isWholeLine : true ,
1416
- className : 'modifiedChangesDecoration' ,
1417
- marginClassName : 'modifiedChangesDecoration' ,
1418
- }
1419
- } ] )
1408
+ const ranges = [
1409
+ new monacoRef . current . Range ( modifiedStartLine , 0 , modifiedEndLine , 1000 ) ,
1410
+ new monacoRef . current . Range ( originalStartLine , 0 , originalEndLine , 1000 )
1411
+ ]
1420
1412
const widgetId = `accept_decline_widget${ index } `
1413
+ const decoratorList = addDecoratorCollection ( widgetId , ranges )
1421
1414
1422
1415
setDecoratorListCollection ( decoratorListCollection => ( { ...decoratorListCollection , [ widgetId ] : decoratorList } ) )
1423
1416
if ( index === 0 ) {
0 commit comments