@@ -8,7 +8,8 @@ import { findLast } from 'vs/base/common/arrays';
8
8
import { onUnexpectedError } from 'vs/base/common/errors' ;
9
9
import { Emitter , Event } from 'vs/base/common/event' ;
10
10
import { IObservable , ISettableObservable , autorun , derived , keepAlive , observableValue , waitForState } from 'vs/base/common/observable' ;
11
- import { disposableObservableValue , transaction } from 'vs/base/common/observableImpl/base' ;
11
+ import { disposableObservableValue } from 'vs/base/common/observableImpl/base' ;
12
+ import { derivedWithStore } from 'vs/base/common/observableImpl/derived' ;
12
13
import { isDefined } from 'vs/base/common/types' ;
13
14
import { Constants } from 'vs/base/common/uint' ;
14
15
import 'vs/css!./style' ;
@@ -80,6 +81,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
80
81
private readonly _rootSizeObserver : ObservableElementSizeObserver ;
81
82
private readonly _options : ISettableObservable < ValidDiffEditorBaseOptions > ;
82
83
private readonly _sash : IObservable < DiffEditorSash | undefined > ;
84
+ private readonly _boundarySashes = observableValue < IBoundarySashes | undefined > ( 'boundarySashes' , undefined ) ;
83
85
private readonly _renderOverviewRuler : IObservable < boolean > ;
84
86
85
87
constructor (
@@ -114,30 +116,30 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
114
116
this . _register ( applyObservableDecorations ( this . _modifiedEditor , this . _decorations . map ( d => d ?. modifiedDecorations || [ ] ) ) ) ;
115
117
116
118
this . _renderOverviewRuler = this . _options . map ( o => o . renderOverviewRuler ) ;
117
- const sash = this . _register ( disposableObservableValue < DiffEditorSash | undefined > ( 'sash' , undefined ) ) ;
118
- this . _sash = sash ;
119
-
120
- this . _register ( autorun ( 'update sash' , reader => {
119
+ this . _sash = derivedWithStore ( 'sash' , ( reader , store ) => {
121
120
const showSash = this . _options . read ( reader ) . renderSideBySide ;
122
-
123
121
this . elements . root . classList . toggle ( 'side-by-side' , showSash ) ;
124
-
125
- transaction ( tx => {
126
- sash . set ( undefined , tx ) ;
127
- if ( showSash ) {
128
- sash . set ( new DiffEditorSash (
129
- this . _options . map ( o => o . enableSplitViewResizing ) ,
130
- this . _options . map ( o => o . splitViewDefaultRatio ) ,
131
- this . elements . root ,
132
- {
133
- height : this . _rootSizeObserver . height ,
134
- width : this . _rootSizeObserver . width . map ( ( w , reader ) => w - ( this . _renderOverviewRuler . read ( reader ) ? OverviewRulerPart . ENTIRE_DIFF_OVERVIEW_WIDTH : 0 ) ) ,
135
- }
136
- ) , tx ) ;
122
+ if ( ! showSash ) {
123
+ return undefined ;
124
+ }
125
+ const result = store . add ( new DiffEditorSash (
126
+ this . _options . map ( o => o . enableSplitViewResizing ) ,
127
+ this . _options . map ( o => o . splitViewDefaultRatio ) ,
128
+ this . elements . root ,
129
+ {
130
+ height : this . _rootSizeObserver . height ,
131
+ width : this . _rootSizeObserver . width . map ( ( w , reader ) => w - ( this . _renderOverviewRuler . read ( reader ) ? OverviewRulerPart . ENTIRE_DIFF_OVERVIEW_WIDTH : 0 ) ) ,
137
132
}
138
- } ) ;
139
- } ) ) ;
140
-
133
+ ) ) ;
134
+ store . add ( autorun ( 'setBoundarySashes' , reader => {
135
+ const boundarySashes = this . _boundarySashes . read ( reader ) ;
136
+ if ( boundarySashes ) {
137
+ result . setBoundarySashes ( boundarySashes ) ;
138
+ }
139
+ } ) ) ;
140
+ return result ;
141
+ } ) ;
142
+ this . _register ( keepAlive ( this . _sash , true ) ) ;
141
143
142
144
this . _register ( new UnchangedRangesFeature ( this . _originalEditor , this . _modifiedEditor , this . _diffModel ) ) ;
143
145
this . _register ( this . _instantiationService . createInstance ( ViewZoneManager , this . _originalEditor , this . _modifiedEditor , this . _diffModel , this . _options . map ( o => o . renderSideBySide ) ) ) ;
@@ -490,13 +492,11 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
490
492
getModifiedEditor ( ) : ICodeEditor { return this . _modifiedEditor ; }
491
493
492
494
setBoundarySashes ( sashes : IBoundarySashes ) : void {
493
- // TODO
494
- this . _sash . get ( ) ?. setBoundarySashes ( sashes ) ;
495
+ this . _boundarySashes . set ( sashes , undefined ) ;
495
496
}
496
497
497
- readonly onDidUpdateDiff : Event < void > = e => {
498
- return { dispose : ( ) => { } } ;
499
- } ;
498
+ private readonly _diffValue = this . _diffModel . map ( ( m , r ) => m ?. diff . read ( r ) ) ;
499
+ readonly onDidUpdateDiff : Event < void > = Event . fromObservableLight ( this . _diffValue ) ;
500
500
501
501
get ignoreTrimWhitespace ( ) : boolean {
502
502
return this . _options . get ( ) . ignoreTrimWhitespace ;
@@ -510,13 +510,73 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
510
510
return this . _options . get ( ) . renderSideBySide ;
511
511
}
512
512
513
+ /**
514
+ * @deprecated Use `this.getDiffComputationResult().changes2` instead.
515
+ */
513
516
getLineChanges ( ) : ILineChange [ ] | null {
514
- return null ;
515
- //throw new Error('Method not implemented.');
517
+ const diffState = this . _diffModel . get ( ) ?. diff . get ( ) ;
518
+ if ( ! diffState ) {
519
+ return null ;
520
+ }
521
+ return diffState . mappings . map ( x => {
522
+ const m = x . lineRangeMapping ;
523
+ let originalStartLineNumber : number ;
524
+ let originalEndLineNumber : number ;
525
+ let modifiedStartLineNumber : number ;
526
+ let modifiedEndLineNumber : number ;
527
+ let innerChanges = m . innerChanges ;
528
+
529
+ if ( m . originalRange . isEmpty ) {
530
+ // Insertion
531
+ originalStartLineNumber = m . originalRange . startLineNumber - 1 ;
532
+ originalEndLineNumber = 0 ;
533
+ innerChanges = undefined ;
534
+ } else {
535
+ originalStartLineNumber = m . originalRange . startLineNumber ;
536
+ originalEndLineNumber = m . originalRange . endLineNumberExclusive - 1 ;
537
+ }
538
+
539
+ if ( m . modifiedRange . isEmpty ) {
540
+ // Deletion
541
+ modifiedStartLineNumber = m . modifiedRange . startLineNumber - 1 ;
542
+ modifiedEndLineNumber = 0 ;
543
+ innerChanges = undefined ;
544
+ } else {
545
+ modifiedStartLineNumber = m . modifiedRange . startLineNumber ;
546
+ modifiedEndLineNumber = m . modifiedRange . endLineNumberExclusive - 1 ;
547
+ }
548
+
549
+ return {
550
+ originalStartLineNumber,
551
+ originalEndLineNumber,
552
+ modifiedStartLineNumber,
553
+ modifiedEndLineNumber,
554
+ charChanges : innerChanges ?. map ( m => ( {
555
+ originalStartLineNumber : m . originalRange . startLineNumber ,
556
+ originalStartColumn : m . originalRange . startColumn ,
557
+ originalEndLineNumber : m . originalRange . endLineNumber ,
558
+ originalEndColumn : m . originalRange . endColumn ,
559
+ modifiedStartLineNumber : m . modifiedRange . startLineNumber ,
560
+ modifiedStartColumn : m . modifiedRange . startColumn ,
561
+ modifiedEndLineNumber : m . modifiedRange . endLineNumber ,
562
+ modifiedEndColumn : m . modifiedRange . endColumn ,
563
+ } ) )
564
+ } ;
565
+ } ) ;
516
566
}
567
+
517
568
getDiffComputationResult ( ) : IDiffComputationResult | null {
518
- return null ;
519
- //throw new Error('Method not implemented.');
569
+ const diffState = this . _diffModel . get ( ) ?. diff . get ( ) ;
570
+ if ( ! diffState ) {
571
+ return null ;
572
+ }
573
+
574
+ return {
575
+ changes : this . getLineChanges ( ) ! ,
576
+ changes2 : diffState . mappings . map ( m => m . lineRangeMapping ) ,
577
+ identical : diffState . identical ,
578
+ quitEarly : diffState . quitEarly ,
579
+ } ;
520
580
}
521
581
522
582
private _goTo ( diff : DiffMapping ) : void {
0 commit comments