@@ -104,56 +104,10 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
104104 ( i , c , o , o2 ) => this . _createInnerEditor ( i , c , o , o2 ) ,
105105 ) ) ;
106106
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-
151107 this . _sash = derivedWithStore ( 'sash' , ( reader , store ) => {
152108 const showSash = this . _options . renderSideBySide . read ( reader ) ;
153109 this . elements . root . classList . toggle ( 'side-by-side' , showSash ) ;
154- if ( ! showSash ) {
155- return undefined ;
156- }
110+ if ( ! showSash ) { return undefined ; }
157111 const result = store . add ( new DiffEditorSash (
158112 this . _options ,
159113 this . elements . root ,
@@ -173,36 +127,25 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
173127 this . _register ( keepAlive ( this . _sash , true ) ) ;
174128
175129 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 ) ) ;
182131 } ) ) ;
183132
184133 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 ) ) ;
191135 } ) ) ;
192136
193137 this . _register ( this . _instantiationService . createInstance (
194138 ViewZoneManager ,
195- this . _editors . original ,
196- this . _editors . modified ,
139+ this . _editors ,
197140 this . _diffModel ,
198141 this . _options ,
199142 this ,
200143 ( ) => this . unchangedRangesFeature . isUpdatingViewZones ,
201144 ) ) ;
202145
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 ,
206149 this . elements . root ,
207150 this . _diffModel ,
208151 this . _rootSizeObserver . width ,
@@ -227,8 +170,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
227170 this . _diffModel ,
228171 this . _layoutInfo . map ( i => i . originalEditor ) ,
229172 this . _layoutInfo . map ( i => i . modifiedEditor ) ,
230- this . _editors . original ,
231- this . _editors . modified ,
173+ this . _editors ,
232174 ) ) ;
233175
234176 this . _register ( applyStyle ( this . elements . overlay , {
@@ -238,6 +180,40 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
238180 ? 'visible' : 'hidden'
239181 ) ,
240182 } ) ) ;
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+ } ) ) ;
241217 }
242218
243219 protected _createInnerEditor ( instantiationService : IInstantiationService , container : HTMLElement , options : Readonly < IEditorConstructionOptions > , editorWidgetOptions : ICodeEditorWidgetOptions ) : CodeEditorWidget {
@@ -307,7 +283,8 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
307283 const modifiedViewState = this . _editors . modified . saveViewState ( ) ;
308284 return {
309285 original : originalViewState ,
310- modified : modifiedViewState
286+ modified : modifiedViewState ,
287+ modelState : this . _diffModel . get ( ) ?. serializeState ( ) ,
311288 } ;
312289 }
313290
@@ -316,6 +293,9 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
316293 const diffEditorState = s as IDiffEditorViewState ;
317294 this . _editors . original . restoreViewState ( diffEditorState . original ) ;
318295 this . _editors . modified . restoreViewState ( diffEditorState . modified ) ;
296+ if ( diffEditorState . modelState ) {
297+ this . _diffModel . get ( ) ?. restoreSerializedState ( diffEditorState . modelState as any ) ;
298+ }
319299 }
320300 }
321301
0 commit comments