-
Notifications
You must be signed in to change notification settings - Fork 1.8k
pull AccessibleBuffer out of AccessibilityManager
#4400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3620f57
test
meganrogge 4cf2523
test 2
meganrogge a993894
testing 3
meganrogge 8c10fda
revert
meganrogge f401f1c
Merge branch 'xtermjs:master' into master
meganrogge 82f2869
Merge branch 'xtermjs:master' into master
meganrogge 5ec9462
pull out accessible buffer
meganrogge d2d3e43
rm unused code
meganrogge 6a5ca43
catch bug
meganrogge 1c3e4dd
rm code
meganrogge b1d4170
rm more code
meganrogge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Copyright (c) 2017 The xterm.js authors. All rights reserved. | ||
| * @license MIT | ||
| */ | ||
|
|
||
| import * as Strings from 'browser/LocalizableStrings'; | ||
| import { ITerminal, IRenderDebouncer, ReadonlyColorSet } from 'browser/Types'; | ||
| import { isMac } from 'common/Platform'; | ||
| import { TimeBasedDebouncer } from 'browser/TimeBasedDebouncer'; | ||
| import { addDisposableDomListener } from 'browser/Lifecycle'; | ||
| import { Disposable, toDisposable } from 'common/Lifecycle'; | ||
| import { IRenderService, IThemeService } from 'browser/services/Services'; | ||
| import { IOptionsService } from 'common/services/Services'; | ||
| import { ITerminalOptions } from 'xterm'; | ||
|
|
||
| export class AccessibleBuffer extends Disposable { | ||
| private _accessiblityBuffer: HTMLElement; | ||
| private _isAccessibilityBufferActive: boolean = false; | ||
| public get isAccessibilityBufferActive(): boolean { return this._isAccessibilityBufferActive; } | ||
|
|
||
| constructor( | ||
| private readonly _terminal: ITerminal, | ||
| @IOptionsService optionsService: IOptionsService, | ||
| @IRenderService private readonly _renderService: IRenderService, | ||
| @IThemeService themeService: IThemeService | ||
| ) { | ||
| super(); | ||
| if (!this._terminal.element) { | ||
| throw new Error('Cannot enable accessibility before Terminal.open'); | ||
| } | ||
|
|
||
| this._accessiblityBuffer = document.createElement('div'); | ||
| this._accessiblityBuffer.setAttribute('role', 'document'); | ||
| this._accessiblityBuffer.ariaRoleDescription = Strings.accessibilityBuffer; | ||
| this._accessiblityBuffer.tabIndex = 0; | ||
| this._accessiblityBuffer.classList.add('xterm-accessibility-buffer'); | ||
| this._terminal.element.insertAdjacentElement('afterbegin', this._accessiblityBuffer); | ||
|
|
||
| this.register(addDisposableDomListener(this._accessiblityBuffer, 'keydown', (ev: KeyboardEvent) => { | ||
| if (ev.key === 'Tab') { | ||
| this._isAccessibilityBufferActive = false; | ||
| }} | ||
| )); | ||
| this.register(addDisposableDomListener(this._accessiblityBuffer, 'focus',() => this._refreshAccessibilityBuffer())); | ||
| this.register(addDisposableDomListener(this._accessiblityBuffer, 'focusout',() => this._isAccessibilityBufferActive = false)); | ||
|
|
||
| this._handleColorChange(themeService.colors); | ||
| this.register(themeService.onChangeColors(e => this._handleColorChange(e))); | ||
| this._handleFontOptionChange(optionsService.options); | ||
| this.register(optionsService.onMultipleOptionChange(['fontSize', 'fontFamily', 'letterSpacing', 'lineHeight'], () => this._handleFontOptionChange(optionsService.options))); | ||
| this.register(toDisposable(() => this._accessiblityBuffer.remove())); | ||
| } | ||
|
|
||
| private _refreshAccessibilityBuffer(): void { | ||
| if (!this._terminal.viewport) { | ||
| return; | ||
| } | ||
| this._isAccessibilityBufferActive = true; | ||
| const { bufferElements } = this._terminal.viewport.getBufferElements(0); | ||
| for (const element of bufferElements) { | ||
| if (element.textContent) { | ||
| element.textContent = element.textContent.replace(new RegExp(' ', 'g'), '\xA0'); | ||
| } | ||
| } | ||
| this._accessiblityBuffer.replaceChildren(...bufferElements); | ||
| this._accessiblityBuffer.scrollTop = this._accessiblityBuffer.scrollHeight; | ||
| } | ||
|
|
||
| private _handleColorChange(colorSet: ReadonlyColorSet): void { | ||
| this._accessiblityBuffer.style.backgroundColor = colorSet.background.css; | ||
| this._accessiblityBuffer.style.color = colorSet.foreground.css; | ||
| } | ||
|
|
||
| private _handleFontOptionChange(options: Required<ITerminalOptions>): void { | ||
| this._accessiblityBuffer.style.fontFamily = options.fontFamily; | ||
| this._accessiblityBuffer.style.fontSize = `${options.fontSize}px`; | ||
| this._accessiblityBuffer.style.lineHeight = `${options.lineHeight * (this._renderService.dimensions.css.cell.height)}px`; | ||
| this._accessiblityBuffer.style.letterSpacing = `${options.letterSpacing}px`; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to put this here so that dimensions from the render service wouldn't be 0. lmk if there's a better place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right function, I'd put it just below the
AccessibilityManagers init to be a little more organized. If you needed to move it here then something must not have been migrated to the new file correctly as it was working before when bundled intoAccessibilityManager.Unless that only worked when toggling screenReaderMode on after Terminal was
opened? In that case there's probably some other event we're not listening to?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's where I put it originally and it didn't work, so seems like we're missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needs to be after this to work