From 5ca15cfe3be47841c9878f4467ab9f1f06fe0d47 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 3 Jan 2018 09:50:03 -0800 Subject: [PATCH] Fix linefeed event This was causing new lines to join words together --- src/AccessibilityManager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/AccessibilityManager.ts b/src/AccessibilityManager.ts index bda634d0..8de8d459 100644 --- a/src/AccessibilityManager.ts +++ b/src/AccessibilityManager.ts @@ -50,14 +50,14 @@ export class AccessibilityManager implements IDisposable { this._addTerminalEventListener('refresh', data => this._refreshRows(data.start, data.end)); // Line feed is an issue as the prompt won't be read out after a command is run this._addTerminalEventListener('a11y.char', (char) => this._onChar(char)); - this._addTerminalEventListener('lineFeed', () => this._onChar('\n')); + this._addTerminalEventListener('linefeed', () => this._onChar('\n')); // Ensure \t is covered, if not a line of output from `ls` is read as one word this._addTerminalEventListener('a11y.tab', () => this._onChar(' ')); this._addTerminalEventListener('charsizechanged', () => this._refreshRowsDimensions()); this._addTerminalEventListener('key', keyChar => this._onKey(keyChar)); this._addTerminalEventListener('blur', () => this._clearLiveRegion()); // TODO: Dispose of this listener when disposed - // TODO: Only refresh when devicePixelRatio changed + // TODO: Only refresh when devicePixelRatio changed (depends on PR #1172) window.addEventListener('resize', () => this._refreshRowsDimensions()); } @@ -97,9 +97,13 @@ export class AccessibilityManager implements IDisposable { private _onChar(char: string): void { if (this._liveRegionLineCount < MAX_ROWS_TO_READ + 1) { + // \n needs to be printed as a space, otherwise it will be collapsed to + // "" in the DOM and the last and first words of the rows will be read + // as a single word if (this._charsToConsume.length > 0) { // Have the screen reader ignore the char if it was just input - if (this._charsToConsume.shift() !== char) { + const shiftedChar = this._charsToConsume.shift(); + if (shiftedChar !== char) { this._liveRegion.textContent += char; } } else {