@@ -15,7 +15,6 @@ import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecy
15
15
import { IObservable , ITransaction , autorun , autorunWithStore , derived , derivedWithStore , observableValue , subtransaction , transaction } from 'vs/base/common/observable' ;
16
16
import { ThemeIcon } from 'vs/base/common/themables' ;
17
17
import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo' ;
18
- import { DiffEditorEditors } from 'vs/editor/browser/widget/diffEditor/components/diffEditorEditors' ;
19
18
import { applyStyle } from 'vs/editor/browser/widget/diffEditor/utils' ;
20
19
import { EditorFontLigatures , EditorOption , IComputedEditorOptions } from 'vs/editor/common/config/editorOptions' ;
21
20
import { LineRange } from 'vs/editor/common/core/lineRange' ;
@@ -34,11 +33,33 @@ import { AccessibilitySignal, IAccessibilitySignalService } from 'vs/platform/ac
34
33
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
35
34
import { registerIcon } from 'vs/platform/theme/common/iconRegistry' ;
36
35
import 'vs/css!./accessibleDiffViewer' ;
36
+ import { DiffEditorEditors } from 'vs/editor/browser/widget/diffEditor/components/diffEditorEditors' ;
37
37
38
38
const accessibleDiffViewerInsertIcon = registerIcon ( 'diff-review-insert' , Codicon . add , localize ( 'accessibleDiffViewerInsertIcon' , 'Icon for \'Insert\' in accessible diff viewer.' ) ) ;
39
39
const accessibleDiffViewerRemoveIcon = registerIcon ( 'diff-review-remove' , Codicon . remove , localize ( 'accessibleDiffViewerRemoveIcon' , 'Icon for \'Remove\' in accessible diff viewer.' ) ) ;
40
40
const accessibleDiffViewerCloseIcon = registerIcon ( 'diff-review-close' , Codicon . close , localize ( 'accessibleDiffViewerCloseIcon' , 'Icon for \'Close\' in accessible diff viewer.' ) ) ;
41
41
42
+ export interface IAccessibleDiffViewerModel {
43
+ getOriginalModel ( ) : ITextModel ;
44
+ getOriginalOptions ( ) : IComputedEditorOptions ;
45
+
46
+ /**
47
+ * Should do: `setSelection`, `revealLine` and `focus`
48
+ */
49
+ originalReveal ( range : Range ) : void ;
50
+
51
+ getModifiedModel ( ) : ITextModel ;
52
+ getModifiedOptions ( ) : IComputedEditorOptions ;
53
+ /**
54
+ * Should do: `setSelection`, `revealLine` and `focus`
55
+ */
56
+ modifiedReveal ( range ?: Range ) : void ;
57
+ modifiedSetSelection ( range : Range ) : void ;
58
+ modifiedFocus ( ) : void ;
59
+
60
+ getModifiedPosition ( ) : Position | undefined ;
61
+ }
62
+
42
63
export class AccessibleDiffViewer extends Disposable {
43
64
public static _ttPolicy = createTrustedTypesPolicy ( 'diffReview' , { createHTML : value => value } ) ;
44
65
@@ -50,7 +71,7 @@ export class AccessibleDiffViewer extends Disposable {
50
71
private readonly _width : IObservable < number > ,
51
72
private readonly _height : IObservable < number > ,
52
73
private readonly _diffs : IObservable < DetailedLineRangeMapping [ ] | undefined > ,
53
- private readonly _editors : DiffEditorEditors ,
74
+ private readonly _models : IAccessibleDiffViewerModel ,
54
75
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
55
76
) {
56
77
super ( ) ;
@@ -62,8 +83,8 @@ export class AccessibleDiffViewer extends Disposable {
62
83
if ( ! visible ) {
63
84
return null ;
64
85
}
65
- const model = store . add ( this . _instantiationService . createInstance ( ViewModel , this . _diffs , this . _editors , this . _setVisible , this . _canClose ) ) ;
66
- const view = store . add ( this . _instantiationService . createInstance ( View , this . _parentNode , model , this . _width , this . _height , this . _editors ) ) ;
86
+ const model = store . add ( this . _instantiationService . createInstance ( ViewModel , this . _diffs , this . _models , this . _setVisible , this . _canClose ) ) ;
87
+ const view = store . add ( this . _instantiationService . createInstance ( View , this . _parentNode , model , this . _width , this . _height , this . _models ) ) ;
67
88
return { model, view, } ;
68
89
} ) . recomputeInitiallyAndOnChange ( this . _store ) ;
69
90
@@ -106,7 +127,7 @@ class ViewModel extends Disposable {
106
127
107
128
constructor (
108
129
private readonly _diffs : IObservable < DetailedLineRangeMapping [ ] | undefined > ,
109
- private readonly _editors : DiffEditorEditors ,
130
+ private readonly _models : IAccessibleDiffViewerModel ,
110
131
private readonly _setVisible : ( visible : boolean , tx : ITransaction | undefined ) => void ,
111
132
public readonly canClose : IObservable < boolean > ,
112
133
@IAccessibilitySignalService private readonly _accessibilitySignalService : IAccessibilitySignalService ,
@@ -123,12 +144,12 @@ class ViewModel extends Disposable {
123
144
124
145
const groups = computeViewElementGroups (
125
146
diffs ,
126
- this . _editors . original . getModel ( ) ! . getLineCount ( ) ,
127
- this . _editors . modified . getModel ( ) ! . getLineCount ( )
147
+ this . _models . getOriginalModel ( ) . getLineCount ( ) ,
148
+ this . _models . getModifiedModel ( ) . getLineCount ( )
128
149
) ;
129
150
130
151
transaction ( tx => {
131
- const p = this . _editors . modified . getPosition ( ) ;
152
+ const p = this . _models . getModifiedPosition ( ) ;
132
153
if ( p ) {
133
154
const nextGroup = groups . findIndex ( g => p ?. lineNumber < g . range . modified . endLineNumberExclusive ) ;
134
155
if ( nextGroup !== - 1 ) {
@@ -155,7 +176,7 @@ class ViewModel extends Disposable {
155
176
const currentViewItem = this . currentElement . read ( reader ) ;
156
177
if ( currentViewItem && currentViewItem . type !== LineType . Header ) {
157
178
const lineNumber = currentViewItem . modifiedLineNumber ?? currentViewItem . diff . modified . startLineNumber ;
158
- this . _editors . modified . setSelection ( Range . fromPositions ( new Position ( lineNumber , 1 ) ) ) ;
179
+ this . _models . modifiedSetSelection ( Range . fromPositions ( new Position ( lineNumber , 1 ) ) ) ;
159
180
}
160
181
} ) ) ;
161
182
}
@@ -194,27 +215,27 @@ class ViewModel extends Disposable {
194
215
}
195
216
196
217
revealCurrentElementInEditor ( ) : void {
218
+ if ( ! this . canClose . get ( ) ) { return ; }
197
219
this . _setVisible ( false , undefined ) ;
198
220
199
221
const curElem = this . currentElement . get ( ) ;
200
222
if ( curElem ) {
201
223
if ( curElem . type === LineType . Deleted ) {
202
- this . _editors . original . setSelection ( Range . fromPositions ( new Position ( curElem . originalLineNumber , 1 ) ) ) ;
203
- this . _editors . original . revealLine ( curElem . originalLineNumber ) ;
204
- this . _editors . original . focus ( ) ;
224
+ this . _models . originalReveal ( Range . fromPositions ( new Position ( curElem . originalLineNumber , 1 ) ) ) ;
205
225
} else {
206
- if ( curElem . type !== LineType . Header ) {
207
- this . _editors . modified . setSelection ( Range . fromPositions ( new Position ( curElem . modifiedLineNumber , 1 ) ) ) ;
208
- this . _editors . modified . revealLine ( curElem . modifiedLineNumber ) ;
209
- }
210
- this . _editors . modified . focus ( ) ;
226
+ this . _models . modifiedReveal (
227
+ curElem . type !== LineType . Header
228
+ ? Range . fromPositions ( new Position ( curElem . modifiedLineNumber , 1 ) )
229
+ : undefined
230
+ ) ;
211
231
}
212
232
}
213
233
}
214
234
215
235
close ( ) : void {
236
+ if ( ! this . canClose . get ( ) ) { return ; }
216
237
this . _setVisible ( false , undefined ) ;
217
- this . _editors . modified . focus ( ) ;
238
+ this . _models . modifiedFocus ( ) ;
218
239
}
219
240
}
220
241
@@ -327,7 +348,7 @@ class View extends Disposable {
327
348
private readonly _model : ViewModel ,
328
349
private readonly _width : IObservable < number > ,
329
350
private readonly _height : IObservable < number > ,
330
- private readonly _editors : DiffEditorEditors ,
351
+ private readonly _models : IAccessibleDiffViewerModel ,
331
352
@ILanguageService private readonly _languageService : ILanguageService ,
332
353
) {
333
354
super ( ) ;
@@ -412,8 +433,8 @@ class View extends Disposable {
412
433
}
413
434
414
435
private _render ( store : DisposableStore ) : void {
415
- const originalOptions = this . _editors . original . getOptions ( ) ;
416
- const modifiedOptions = this . _editors . modified . getOptions ( ) ;
436
+ const originalOptions = this . _models . getOriginalOptions ( ) ;
437
+ const modifiedOptions = this . _models . getModifiedOptions ( ) ;
417
438
418
439
const container = document . createElement ( 'div' ) ;
419
440
container . className = 'diff-review-table' ;
@@ -423,8 +444,8 @@ class View extends Disposable {
423
444
424
445
reset ( this . _content , container ) ;
425
446
426
- const originalModel = this . _editors . original . getModel ( ) ;
427
- const modifiedModel = this . _editors . modified . getModel ( ) ;
447
+ const originalModel = this . _models . getOriginalModel ( ) ;
448
+ const modifiedModel = this . _models . getModifiedModel ( ) ;
428
449
if ( ! originalModel || ! modifiedModel ) {
429
450
return ;
430
451
}
@@ -659,3 +680,49 @@ class View extends Disposable {
659
680
return r . html ;
660
681
}
661
682
}
683
+
684
+ export class AccessibleDiffViewerModelFromEditors implements IAccessibleDiffViewerModel {
685
+ constructor ( private readonly editors : DiffEditorEditors ) { }
686
+
687
+ getOriginalModel ( ) : ITextModel {
688
+ return this . editors . original . getModel ( ) ! ;
689
+ }
690
+
691
+ getOriginalOptions ( ) : IComputedEditorOptions {
692
+ return this . editors . original . getOptions ( ) ;
693
+ }
694
+
695
+ originalReveal ( range : Range ) : void {
696
+ this . editors . original . revealRange ( range ) ;
697
+ this . editors . original . setSelection ( range ) ;
698
+ this . editors . original . focus ( ) ;
699
+ }
700
+
701
+ getModifiedModel ( ) : ITextModel {
702
+ return this . editors . modified . getModel ( ) ! ;
703
+ }
704
+
705
+ getModifiedOptions ( ) : IComputedEditorOptions {
706
+ return this . editors . modified . getOptions ( ) ;
707
+ }
708
+
709
+ modifiedReveal ( range ?: Range | undefined ) : void {
710
+ if ( range ) {
711
+ this . editors . modified . revealRange ( range ) ;
712
+ this . editors . modified . setSelection ( range ) ;
713
+ }
714
+ this . editors . modified . focus ( ) ;
715
+ }
716
+
717
+ modifiedSetSelection ( range : Range ) : void {
718
+ this . editors . modified . setSelection ( range ) ;
719
+ }
720
+
721
+ modifiedFocus ( ) : void {
722
+ this . editors . modified . focus ( ) ;
723
+ }
724
+
725
+ getModifiedPosition ( ) : Position | undefined {
726
+ return this . editors . modified . getPosition ( ) ?? undefined ;
727
+ }
728
+ }
0 commit comments