@@ -76,6 +76,8 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget {
7676
7777 this . _modifiedCode = newText ;
7878 this . _newSource = newText ;
79+
80+ this . _renderMergeButtons ( ) ;
7981 }
8082 } )
8183 ]
@@ -95,17 +97,32 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget {
9597 const editorA = this . _splitView . a ;
9698 const editorB = this . _splitView . b ;
9799
98- const result = getChunks ( editorA . state ) ;
99- const chunks = result ?. chunks ;
100+ const result = getChunks ( editorB . state ) ;
101+ const chunks = result ?. chunks ?? [ ] ;
100102
101- if ( ! chunks || chunks . length === 0 ) {
102- return ;
103- }
103+ const updatedSet = new Set < string > ( ) ;
104+ chunks . forEach ( ( chunk : any ) => {
105+ const id = `${ chunk . fromA } -${ chunk . toA } ` ;
106+ updatedSet . add ( id ) ;
107+
108+ if ( ! this . _activeChunks . has ( id ) ) {
109+ this . _activeChunks . add ( id ) ;
110+ }
111+ } ) ;
104112
113+ for ( const id of this . _activeChunks ) {
114+ if ( ! updatedSet . has ( id ) ) {
115+ this . _activeChunks . delete ( id ) ;
116+ }
117+ }
105118 const builder = new RangeSetBuilder < Decoration > ( ) ;
106119
107120 chunks . forEach ( ( chunk : any ) => {
108121 const { fromA, toA, fromB, toB } = chunk ;
122+ const id = `${ fromA } -${ toA } ` ;
123+
124+ // eslint-disable-next-line @typescript-eslint/no-this-alias
125+ const diffWidget = this ;
109126
110127 const arrowWidget = Decoration . widget ( {
111128 widget : new ( class extends WidgetType {
@@ -119,13 +136,9 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget {
119136 editorB . dispatch ( {
120137 changes : { from : fromB , to : toB , insert : origText }
121138 } ) ;
122- editorA . dispatch ( {
123- effects : addSplitDiffDecorations . of (
124- editorA . state . field ( splitDiffDecorationField ) . update ( {
125- filter : ( from , to , value ) => from !== fromA
126- } )
127- )
128- } ) ;
139+
140+ diffWidget . _activeChunks . delete ( id ) ;
141+ diffWidget . _renderMergeButtons ( ) ;
129142 } ;
130143 return btn ;
131144 }
@@ -150,6 +163,7 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget {
150163
151164 private _originalCode : string ;
152165 private _modifiedCode : string ;
166+ private _activeChunks = new Set < string > ( ) ;
153167
154168 private _splitView ! : MergeView & {
155169 a : EditorView ;
0 commit comments