@@ -9,10 +9,8 @@ import { registerDiffEditorContribution } from 'vs/editor/browser/editorExtensio
9
9
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
10
10
import { DiffReviewNext , DiffReviewPrev } from 'vs/editor/browser/widget/diffEditor.contribution' ;
11
11
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2' ;
12
- import { EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget' ;
13
- import { IDiffComputationResult } from 'vs/editor/common/diff/smartLinesDiffComputer' ;
12
+ import { EmbeddedDiffEditorWidget , EmbeddedDiffEditorWidget2 } from 'vs/editor/browser/widget/embeddedCodeEditorWidget' ;
14
13
import { IDiffEditorContribution } from 'vs/editor/common/editorCommon' ;
15
- import * as nls from 'vs/nls' ;
16
14
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
17
15
import { ContextKeyEqualsExpr , ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
18
16
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -22,20 +20,13 @@ import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor';
22
20
import { AccessibilityHelpAction } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution' ;
23
21
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
24
22
import { AccessibleViewType , IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView' ;
25
-
26
- const enum WidgetState {
27
- Hidden ,
28
- HintWhitespace
29
- }
23
+ import { localize } from 'vs/nls' ;
24
+ import { observableFromEvent } from 'vs/base/common/observable' ;
25
+ import { autorunWithStore2 } from 'vs/base/common/observableImpl/autorun' ;
30
26
31
27
class DiffEditorHelperContribution extends Disposable implements IDiffEditorContribution {
32
-
33
28
public static readonly ID = 'editor.contrib.diffEditorHelper' ;
34
29
35
- private _helperWidget : FloatingClickWidget | null ;
36
- private _helperWidgetListener : IDisposable | null ;
37
- private _state : WidgetState ;
38
-
39
30
constructor (
40
31
private readonly _diffEditor : IDiffEditor ,
41
32
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
@@ -46,21 +37,36 @@ class DiffEditorHelperContribution extends Disposable implements IDiffEditorCont
46
37
47
38
this . _register ( createScreenReaderHelp ( ) ) ;
48
39
49
- this . _helperWidget = null ;
50
- this . _helperWidgetListener = null ;
51
- this . _state = WidgetState . Hidden ;
40
+ const isEmbeddedDiffEditor = ( this . _diffEditor instanceof EmbeddedDiffEditorWidget ) || ( this . _diffEditor instanceof EmbeddedDiffEditorWidget2 ) ;
41
+
42
+ if ( ! isEmbeddedDiffEditor ) {
43
+ const computationResult = observableFromEvent ( e => this . _diffEditor . onDidUpdateDiff ( e ) , ( ) => this . _diffEditor . getDiffComputationResult ( ) ) ;
44
+ const onlyWhiteSpaceChange = computationResult . map ( r => r && ! r . identical && r . changes2 . length === 0 ) ;
45
+
46
+ this . _register ( autorunWithStore2 ( 'update state' , ( reader , store ) => {
47
+ if ( onlyWhiteSpaceChange . read ( reader ) ) {
48
+ const helperWidget = store . add ( this . _instantiationService . createInstance (
49
+ FloatingClickWidget ,
50
+ this . _diffEditor . getModifiedEditor ( ) ,
51
+ localize ( 'hintWhitespace' , "Show Whitespace Differences" ) ,
52
+ null
53
+ ) ) ;
54
+ store . add ( helperWidget . onClick ( ( ) => {
55
+ this . _configurationService . updateValue ( 'diffEditor.ignoreTrimWhitespace' , false ) ;
56
+ } ) ) ;
57
+ helperWidget . render ( ) ;
58
+ }
59
+ } ) ) ;
52
60
53
- if ( ! ( this . _diffEditor instanceof EmbeddedDiffEditorWidget ) ) {
54
61
this . _register ( this . _diffEditor . onDidUpdateDiff ( ( ) => {
55
62
const diffComputationResult = this . _diffEditor . getDiffComputationResult ( ) ;
56
- this . _setState ( this . _deduceState ( diffComputationResult ) ) ;
57
63
58
64
if ( diffComputationResult && diffComputationResult . quitEarly ) {
59
65
this . _notificationService . prompt (
60
66
Severity . Warning ,
61
- nls . localize ( 'hintTimeout' , "The diff algorithm was stopped early (after {0} ms.)" , this . _diffEditor . maxComputationTime ) ,
67
+ localize ( 'hintTimeout' , "The diff algorithm was stopped early (after {0} ms.)" , this . _diffEditor . maxComputationTime ) ,
62
68
[ {
63
- label : nls . localize ( 'removeTimeout' , "Remove Limit" ) ,
69
+ label : localize ( 'removeTimeout' , "Remove Limit" ) ,
64
70
run : ( ) => {
65
71
this . _configurationService . updateValue ( 'diffEditor.maxComputationTime' , 0 ) ;
66
72
}
@@ -71,49 +77,6 @@ class DiffEditorHelperContribution extends Disposable implements IDiffEditorCont
71
77
} ) ) ;
72
78
}
73
79
}
74
-
75
- private _deduceState ( diffComputationResult : IDiffComputationResult | null ) : WidgetState {
76
- if ( ! diffComputationResult ) {
77
- return WidgetState . Hidden ;
78
- }
79
- if ( this . _diffEditor . ignoreTrimWhitespace && diffComputationResult . changes . length === 0 && ! diffComputationResult . identical ) {
80
- return WidgetState . HintWhitespace ;
81
- }
82
- return WidgetState . Hidden ;
83
- }
84
-
85
- private _setState ( newState : WidgetState ) {
86
- if ( this . _state === newState ) {
87
- return ;
88
- }
89
-
90
- this . _state = newState ;
91
-
92
- if ( this . _helperWidgetListener ) {
93
- this . _helperWidgetListener . dispose ( ) ;
94
- this . _helperWidgetListener = null ;
95
- }
96
- if ( this . _helperWidget ) {
97
- this . _helperWidget . dispose ( ) ;
98
- this . _helperWidget = null ;
99
- }
100
-
101
- if ( this . _state === WidgetState . HintWhitespace ) {
102
- this . _helperWidget = this . _instantiationService . createInstance ( FloatingClickWidget , this . _diffEditor . getModifiedEditor ( ) , nls . localize ( 'hintWhitespace' , "Show Whitespace Differences" ) , null ) ;
103
- this . _helperWidgetListener = this . _helperWidget . onClick ( ( ) => this . _onDidClickHelperWidget ( ) ) ;
104
- this . _helperWidget . render ( ) ;
105
- }
106
- }
107
-
108
- private _onDidClickHelperWidget ( ) : void {
109
- if ( this . _state === WidgetState . HintWhitespace ) {
110
- this . _configurationService . updateValue ( 'diffEditor.ignoreTrimWhitespace' , false ) ;
111
- }
112
- }
113
-
114
- override dispose ( ) : void {
115
- super . dispose ( ) ;
116
- }
117
80
}
118
81
119
82
function createScreenReaderHelp ( ) : IDisposable {
@@ -140,14 +103,14 @@ function createScreenReaderHelp(): IDisposable {
140
103
accessibleViewService . show ( {
141
104
verbositySettingKey : 'diffEditor' ,
142
105
provideContent : ( ) => [
143
- nls . localize ( 'msg1' , "You are in a diff editor." ) ,
144
- nls . localize ( 'msg2' , "Press {0} or {1} to view the next or previous diff in the diff review mode that is optimized for screen readers." , next , previous ) ,
145
- nls . localize ( 'msg3' , "To control which audio cues should be played, the following settings can be configured: {0}." , keys . join ( ', ' ) ) ,
106
+ localize ( 'msg1' , "You are in a diff editor." ) ,
107
+ localize ( 'msg2' , "Press {0} or {1} to view the next or previous diff in the diff review mode that is optimized for screen readers." , next , previous ) ,
108
+ localize ( 'msg3' , "To control which audio cues should be played, the following settings can be configured: {0}." , keys . join ( ', ' ) ) ,
146
109
] . join ( '\n' ) ,
147
110
onClose : ( ) => {
148
111
codeEditor . focus ( ) ;
149
112
} ,
150
- options : { type : AccessibleViewType . HelpMenu , ariaLabel : nls . localize ( 'chat-help-label' , "Diff editor accessibility help" ) }
113
+ options : { type : AccessibleViewType . HelpMenu , ariaLabel : localize ( 'chat-help-label' , "Diff editor accessibility help" ) }
151
114
} ) ;
152
115
} , ContextKeyExpr . and (
153
116
ContextKeyEqualsExpr . create ( 'diffEditorVersion' , 2 ) ,
0 commit comments