55'use strict' ;
66
77import 'vs/css!./textAreaHandler' ;
8+ import * as platform from 'vs/base/common/platform' ;
89import * as browser from 'vs/base/browser/browser' ;
910import { TextAreaInput , ITextAreaInputHost , IPasteData , ICompositionData } from 'vs/editor/browser/controller/textAreaInput' ;
1011import { ISimpleModel , ITypeData , TextAreaState , IENarratorStrategy , NVDAPagedStrategy } from 'vs/editor/browser/controller/textAreaState' ;
@@ -54,6 +55,7 @@ export class TextAreaHandler extends ViewPart {
5455 private readonly _viewHelper : ITextAreaHandlerHelper ;
5556
5657 private _pixelRatio : number ;
58+ private _accessibilitySupport : platform . AccessibilitySupport ;
5759 private _contentLeft : number ;
5860 private _contentWidth : number ;
5961 private _contentHeight : number ;
@@ -85,6 +87,7 @@ export class TextAreaHandler extends ViewPart {
8587 const conf = this . _context . configuration . editor ;
8688
8789 this . _pixelRatio = conf . pixelRatio ;
90+ this . _accessibilitySupport = conf . accessibilitySupport ;
8891 this . _contentLeft = conf . layoutInfo . contentLeft ;
8992 this . _contentWidth = conf . layoutInfo . contentWidth ;
9093 this . _contentHeight = conf . layoutInfo . contentHeight ;
@@ -160,6 +163,11 @@ export class TextAreaHandler extends ViewPart {
160163 return TextAreaState . EMPTY ;
161164 }
162165
166+ if ( this . _accessibilitySupport === platform . AccessibilitySupport . Disabled ) {
167+ // We know for a fact that a screen reader is not attached
168+ return TextAreaState . EMPTY ;
169+ }
170+
163171 const selection = this . _selections [ 0 ] ;
164172
165173 if ( this . _experimentalScreenReader ) {
@@ -286,6 +294,10 @@ export class TextAreaHandler extends ViewPart {
286294 if ( e . pixelRatio ) {
287295 this . _pixelRatio = conf . pixelRatio ;
288296 }
297+ if ( e . accessibilitySupport ) {
298+ this . _accessibilitySupport = conf . accessibilitySupport ;
299+ this . _textAreaInput . writeScreenReaderContent ( 'strategy changed' ) ;
300+ }
289301 if ( e . emptySelectionClipboard ) {
290302 this . _emptySelectionClipboard = conf . emptySelectionClipboard ;
291303 }
@@ -294,6 +306,7 @@ export class TextAreaHandler extends ViewPart {
294306 }
295307 public onCursorStateChanged ( e : viewEvents . ViewCursorStateChangedEvent ) : boolean {
296308 this . _selections = e . selections . slice ( 0 ) ;
309+ this . _textAreaInput . writeScreenReaderContent ( 'selection changed' ) ;
297310 return true ;
298311 }
299312 public onDecorationsChanged ( e : viewEvents . ViewDecorationsChangedEvent ) : boolean {
@@ -333,10 +346,6 @@ export class TextAreaHandler extends ViewPart {
333346 this . _textAreaInput . focusTextArea ( ) ;
334347 }
335348
336- public writeToTextArea ( ) : void {
337- this . _textAreaInput . writeScreenReaderContent ( 'selection changed' ) ;
338- }
339-
340349 public setAriaActiveDescendant ( id : string ) : void {
341350 if ( id ) {
342351 this . textArea . setAttribute ( 'role' , 'combobox' ) ;
@@ -356,11 +365,18 @@ export class TextAreaHandler extends ViewPart {
356365 private _primaryCursorVisibleRange : HorizontalRange = null ;
357366
358367 public prepareRender ( ctx : RenderingContext ) : void {
359- const primaryCursorPosition = new Position ( this . _selections [ 0 ] . positionLineNumber , this . _selections [ 0 ] . positionColumn ) ;
360- this . _primaryCursorVisibleRange = ctx . visibleRangeForPosition ( primaryCursorPosition ) ;
368+ if ( this . _accessibilitySupport === platform . AccessibilitySupport . Enabled ) {
369+ // Do not move the textarea with the cursor, as this generates accessibility events that might confuse screen readers
370+ // See https://github.com/Microsoft/vscode/issues/26730
371+ this . _primaryCursorVisibleRange = null ;
372+ } else {
373+ const primaryCursorPosition = new Position ( this . _selections [ 0 ] . positionLineNumber , this . _selections [ 0 ] . positionColumn ) ;
374+ this . _primaryCursorVisibleRange = ctx . visibleRangeForPosition ( primaryCursorPosition ) ;
375+ }
361376 }
362377
363378 public render ( ctx : RestrictedRenderingContext ) : void {
379+ this . _textAreaInput . writeScreenReaderContent ( 'render' ) ;
364380 this . _render ( ) ;
365381 }
366382
0 commit comments