@@ -104,56 +104,10 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
104
104
( i , c , o , o2 ) => this . _createInnerEditor ( i , c , o , o2 ) ,
105
105
) ) ;
106
106
107
-
108
- this . _register ( this . _editors . original . onDidChangeCursorPosition ( e => {
109
- const m = this . _diffModel . get ( ) ;
110
- if ( ! m ) { return ; }
111
-
112
- const movedText = m . diff . get ( ) ! . movedTexts . find ( m => m . lineRangeMapping . originalRange . contains ( e . position . lineNumber ) ) ;
113
- m . syncedMovedTexts . set ( movedText , undefined ) ;
114
- } ) ) ;
115
- this . _register ( this . _editors . modified . onDidChangeCursorPosition ( e => {
116
- const m = this . _diffModel . get ( ) ;
117
- if ( ! m ) { return ; }
118
-
119
- const movedText = m . diff . get ( ) ! . movedTexts . find ( m => m . lineRangeMapping . modifiedRange . contains ( e . position . lineNumber ) ) ;
120
- m . syncedMovedTexts . set ( movedText , undefined ) ;
121
- } ) ) ;
122
- // Revert change when an arrow is clicked.
123
- this . _register ( this . _editors . modified . onMouseDown ( event => {
124
- if ( ! event . event . rightButton && event . target . position && event . target . element ?. className . includes ( 'arrow-revert-change' ) ) {
125
- const lineNumber = event . target . position . lineNumber ;
126
- const viewZone = event . target as IMouseTargetViewZone | undefined ;
127
-
128
- const model = this . _diffModel . get ( ) ;
129
- if ( ! model ) {
130
- return ;
131
- }
132
- const diffs = model . diff . get ( ) ?. mappings ;
133
- if ( ! diffs ) {
134
- return ;
135
- }
136
- const diff = diffs . find ( d =>
137
- viewZone ?. detail . afterLineNumber === d . lineRangeMapping . modifiedRange . startLineNumber - 1 ||
138
- d . lineRangeMapping . modifiedRange . startLineNumber === lineNumber
139
- ) ;
140
- if ( ! diff ) {
141
- return ;
142
- }
143
- this . revert ( diff . lineRangeMapping ) ;
144
-
145
- event . event . stopPropagation ( ) ;
146
- return ;
147
- }
148
- } ) ) ;
149
-
150
-
151
107
this . _sash = derivedWithStore ( 'sash' , ( reader , store ) => {
152
108
const showSash = this . _options . renderSideBySide . read ( reader ) ;
153
109
this . elements . root . classList . toggle ( 'side-by-side' , showSash ) ;
154
- if ( ! showSash ) {
155
- return undefined ;
156
- }
110
+ if ( ! showSash ) { return undefined ; }
157
111
const result = store . add ( new DiffEditorSash (
158
112
this . _options ,
159
113
this . elements . root ,
@@ -173,36 +127,25 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
173
127
this . _register ( keepAlive ( this . _sash , true ) ) ;
174
128
175
129
this . _register ( autorunWithStore2 ( 'unchangedRangesFeature' , ( reader , store ) => {
176
- this . unchangedRangesFeature = store . add ( new ( readHotReloadableExport ( UnchangedRangesFeature , reader ) ) (
177
- this . _editors . original ,
178
- this . _editors . modified ,
179
- this . _diffModel ,
180
- this . _options . renderSideBySide ,
181
- ) ) ;
130
+ this . unchangedRangesFeature = store . add ( new ( readHotReloadableExport ( UnchangedRangesFeature , reader ) ) ( this . _editors , this . _diffModel , this . _options ) ) ;
182
131
} ) ) ;
183
132
184
133
this . _register ( autorunWithStore2 ( 'decorations' , ( reader , store ) => {
185
- store . add ( new ( readHotReloadableExport ( DiffEditorDecorations , reader ) ) (
186
- this . _editors . original ,
187
- this . _editors . modified ,
188
- this . _diffModel ,
189
- this . _options ,
190
- ) ) ;
134
+ store . add ( new ( readHotReloadableExport ( DiffEditorDecorations , reader ) ) ( this . _editors , this . _diffModel , this . _options ) ) ;
191
135
} ) ) ;
192
136
193
137
this . _register ( this . _instantiationService . createInstance (
194
138
ViewZoneManager ,
195
- this . _editors . original ,
196
- this . _editors . modified ,
139
+ this . _editors ,
197
140
this . _diffModel ,
198
141
this . _options ,
199
142
this ,
200
143
( ) => this . unchangedRangesFeature . isUpdatingViewZones ,
201
144
) ) ;
202
145
203
- this . _register ( this . _instantiationService . createInstance ( OverviewRulerPart ,
204
- this . _editors . original ,
205
- this . _editors . modified ,
146
+ this . _register ( this . _instantiationService . createInstance (
147
+ OverviewRulerPart ,
148
+ this . _editors ,
206
149
this . elements . root ,
207
150
this . _diffModel ,
208
151
this . _rootSizeObserver . width ,
@@ -227,8 +170,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
227
170
this . _diffModel ,
228
171
this . _layoutInfo . map ( i => i . originalEditor ) ,
229
172
this . _layoutInfo . map ( i => i . modifiedEditor ) ,
230
- this . _editors . original ,
231
- this . _editors . modified ,
173
+ this . _editors ,
232
174
) ) ;
233
175
234
176
this . _register ( applyStyle ( this . elements . overlay , {
@@ -238,6 +180,40 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
238
180
? 'visible' : 'hidden'
239
181
) ,
240
182
} ) ) ;
183
+
184
+ this . _register ( this . _editors . original . onDidChangeCursorPosition ( e => {
185
+ const m = this . _diffModel . get ( ) ;
186
+ if ( ! m ) { return ; }
187
+ const movedText = m . diff . get ( ) ! . movedTexts . find ( m => m . lineRangeMapping . originalRange . contains ( e . position . lineNumber ) ) ;
188
+ m . syncedMovedTexts . set ( movedText , undefined ) ;
189
+ } ) ) ;
190
+ this . _register ( this . _editors . modified . onDidChangeCursorPosition ( e => {
191
+ const m = this . _diffModel . get ( ) ;
192
+ if ( ! m ) { return ; }
193
+ const movedText = m . diff . get ( ) ! . movedTexts . find ( m => m . lineRangeMapping . modifiedRange . contains ( e . position . lineNumber ) ) ;
194
+ m . syncedMovedTexts . set ( movedText , undefined ) ;
195
+ } ) ) ;
196
+
197
+ // Revert change when an arrow is clicked.
198
+ this . _register ( this . _editors . modified . onMouseDown ( event => {
199
+ if ( ! event . event . rightButton && event . target . position && event . target . element ?. className . includes ( 'arrow-revert-change' ) ) {
200
+ const lineNumber = event . target . position . lineNumber ;
201
+ const viewZone = event . target as IMouseTargetViewZone | undefined ;
202
+
203
+ const model = this . _diffModel . get ( ) ;
204
+ if ( ! model ) { return ; }
205
+ const diffs = model . diff . get ( ) ?. mappings ;
206
+ if ( ! diffs ) { return ; }
207
+ const diff = diffs . find ( d =>
208
+ viewZone ?. detail . afterLineNumber === d . lineRangeMapping . modifiedRange . startLineNumber - 1 ||
209
+ d . lineRangeMapping . modifiedRange . startLineNumber === lineNumber
210
+ ) ;
211
+ if ( ! diff ) { return ; }
212
+ this . revert ( diff . lineRangeMapping ) ;
213
+
214
+ event . event . stopPropagation ( ) ;
215
+ }
216
+ } ) ) ;
241
217
}
242
218
243
219
protected _createInnerEditor ( instantiationService : IInstantiationService , container : HTMLElement , options : Readonly < IEditorConstructionOptions > , editorWidgetOptions : ICodeEditorWidgetOptions ) : CodeEditorWidget {
@@ -307,7 +283,8 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
307
283
const modifiedViewState = this . _editors . modified . saveViewState ( ) ;
308
284
return {
309
285
original : originalViewState ,
310
- modified : modifiedViewState
286
+ modified : modifiedViewState ,
287
+ modelState : this . _diffModel . get ( ) ?. serializeState ( ) ,
311
288
} ;
312
289
}
313
290
@@ -316,6 +293,9 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
316
293
const diffEditorState = s as IDiffEditorViewState ;
317
294
this . _editors . original . restoreViewState ( diffEditorState . original ) ;
318
295
this . _editors . modified . restoreViewState ( diffEditorState . modified ) ;
296
+ if ( diffEditorState . modelState ) {
297
+ this . _diffModel . get ( ) ?. restoreSerializedState ( diffEditorState . modelState as any ) ;
298
+ }
319
299
}
320
300
}
321
301
0 commit comments