@@ -11,13 +11,15 @@ import { inputLatency } from 'vs/base/browser/performance';
11
11
import { RunOnceScheduler } from 'vs/base/common/async' ;
12
12
import { Emitter , Event } from 'vs/base/common/event' ;
13
13
import { KeyCode } from 'vs/base/common/keyCodes' ;
14
- import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
14
+ import { Disposable , IDisposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
15
15
import { Mimes } from 'vs/base/common/mime' ;
16
16
import { OperatingSystem } from 'vs/base/common/platform' ;
17
17
import * as strings from 'vs/base/common/strings' ;
18
18
import { ITextAreaWrapper , ITypeData , TextAreaState , _debugComposition } from 'vs/editor/browser/controller/textAreaState' ;
19
19
import { Position } from 'vs/editor/common/core/position' ;
20
20
import { Selection } from 'vs/editor/common/core/selection' ;
21
+ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
22
+ import { ILogService } from 'vs/platform/log/common/log' ;
21
23
22
24
export namespace TextAreaSyntethicEvents {
23
25
export const Tap = '-monaco-textarea-synthetic-tap' ;
@@ -193,7 +195,8 @@ export class TextAreaInput extends Disposable {
193
195
// ---
194
196
195
197
private readonly _asyncTriggerCut : RunOnceScheduler ;
196
- private readonly _asyncFocusGainWriteScreenReaderContent : RunOnceScheduler ;
198
+
199
+ private _asyncFocusGainWriteScreenReaderContent : MutableDisposable < RunOnceScheduler > = this . _register ( new MutableDisposable ( ) ) ;
197
200
198
201
private _textAreaState : TextAreaState ;
199
202
@@ -210,16 +213,24 @@ export class TextAreaInput extends Disposable {
210
213
private readonly _host : ITextAreaInputHost ,
211
214
private readonly _textArea : ICompleteTextAreaWrapper ,
212
215
private readonly _OS : OperatingSystem ,
213
- private readonly _browser : IBrowser
216
+ private readonly _browser : IBrowser ,
217
+ @IAccessibilityService private readonly _accessibilityService : IAccessibilityService ,
218
+ @ILogService private readonly _logService : ILogService
214
219
) {
215
220
super ( ) ;
216
221
this . _asyncTriggerCut = this . _register ( new RunOnceScheduler ( ( ) => this . _onCut . fire ( ) , 0 ) ) ;
217
- this . _asyncFocusGainWriteScreenReaderContent = this . _register ( new RunOnceScheduler ( ( ) => this . writeScreenReaderContent ( 'asyncFocusGain' ) , 0 ) ) ;
218
-
219
222
this . _textAreaState = TextAreaState . EMPTY ;
220
223
this . _selectionChangeListener = null ;
221
- this . writeScreenReaderContent ( 'ctor' ) ;
222
-
224
+ if ( this . _accessibilityService . isScreenReaderOptimized ( ) ) {
225
+ this . writeNativeTextAreaContent ( 'ctor' ) ;
226
+ }
227
+ this . _register ( Event . runAndSubscribe ( this . _accessibilityService . onDidChangeScreenReaderOptimized , ( ) => {
228
+ if ( this . _accessibilityService . isScreenReaderOptimized ( ) && ! this . _asyncFocusGainWriteScreenReaderContent . value ) {
229
+ this . _asyncFocusGainWriteScreenReaderContent . value = this . _register ( new RunOnceScheduler ( ( ) => this . writeNativeTextAreaContent ( 'asyncFocusGain' ) , 0 ) ) ;
230
+ } else {
231
+ this . _asyncFocusGainWriteScreenReaderContent . clear ( ) ;
232
+ }
233
+ } ) ) ;
223
234
this . _hasFocus = false ;
224
235
this . _currentComposition = null ;
225
236
@@ -431,10 +442,13 @@ export class TextAreaInput extends Disposable {
431
442
432
443
this . _setHasFocus ( true ) ;
433
444
434
- if ( this . _browser . isSafari && ! hadFocus && this . _hasFocus ) {
445
+ if ( this . _accessibilityService . isScreenReaderOptimized ( ) && this . _browser . isSafari && ! hadFocus && this . _hasFocus ) {
435
446
// When "tabbing into" the textarea, immediately after dispatching the 'focus' event,
436
447
// Safari will always move the selection at offset 0 in the textarea
437
- this . _asyncFocusGainWriteScreenReaderContent . schedule ( ) ;
448
+ if ( ! this . _asyncFocusGainWriteScreenReaderContent . value ) {
449
+ this . _asyncFocusGainWriteScreenReaderContent . value = new RunOnceScheduler ( ( ) => this . writeNativeTextAreaContent ( 'asyncFocusGain' ) , 0 ) ;
450
+ }
451
+ this . _asyncFocusGainWriteScreenReaderContent . value . schedule ( ) ;
438
452
}
439
453
} ) ) ;
440
454
this . _register ( this . _textArea . onBlur ( ( ) => {
@@ -447,7 +461,7 @@ export class TextAreaInput extends Disposable {
447
461
this . _currentComposition = null ;
448
462
449
463
// Clear the textarea to avoid an unwanted cursor type
450
- this . writeScreenReaderContent ( 'blurWithoutCompositionEnd' ) ;
464
+ this . writeNativeTextAreaContent ( 'blurWithoutCompositionEnd' ) ;
451
465
452
466
// Fire artificial composition end
453
467
this . _onCompositionEnd . fire ( ) ;
@@ -463,7 +477,7 @@ export class TextAreaInput extends Disposable {
463
477
this . _currentComposition = null ;
464
478
465
479
// Clear the textarea to avoid an unwanted cursor type
466
- this . writeScreenReaderContent ( 'tapWithoutCompositionEnd' ) ;
480
+ this . writeNativeTextAreaContent ( 'tapWithoutCompositionEnd' ) ;
467
481
468
482
// Fire artificial composition end
469
483
this . _onCompositionEnd . fire ( ) ;
@@ -602,7 +616,7 @@ export class TextAreaInput extends Disposable {
602
616
}
603
617
604
618
if ( this . _hasFocus ) {
605
- this . writeScreenReaderContent ( 'focusgain' ) ;
619
+ this . writeNativeTextAreaContent ( 'focusgain' ) ;
606
620
}
607
621
608
622
if ( this . _hasFocus ) {
@@ -621,12 +635,13 @@ export class TextAreaInput extends Disposable {
621
635
this . _textAreaState = textAreaState ;
622
636
}
623
637
624
- public writeScreenReaderContent ( reason : string ) : void {
625
- if ( this . _currentComposition ) {
638
+ public writeNativeTextAreaContent ( reason : string ) : void {
639
+ if ( ( ! this . _accessibilityService . isScreenReaderOptimized ( ) && reason === 'render' ) || this . _currentComposition ) {
640
+ // Do not write to the text on render unless a screen reader is being used #192278
626
641
// Do not write to the text area when doing composition
627
642
return ;
628
643
}
629
-
644
+ this . _logService . trace ( `writeTextAreaState(reason: ${ reason } )` ) ;
630
645
this . _setAndWriteTextAreaState ( reason , this . _host . getScreenReaderContent ( ) ) ;
631
646
}
632
647
0 commit comments