This commit is contained in:
Joao Moreno
2018-02-28 15:26:14 +01:00
parent 10438e9c5d
commit 2395b9ca93
+47
View File
@@ -325,6 +325,51 @@ class KeyboardController<T> implements IDisposable {
}
}
class DOMFocusController<T> implements IDisposable {
private disposables: IDisposable[] = [];
constructor(
private list: List<T>,
private view: ListView<T>
) {
this.disposables = [];
const onKeyDown = chain(domEvent(view.domNode, 'keydown'))
.filter(e => !isInputElement(e.target as HTMLElement))
.map(e => new StandardKeyboardEvent(e));
onKeyDown.filter(e => e.keyCode === KeyCode.Tab).on(this.onTab, this, this.disposables);
}
private onTab(e: StandardKeyboardEvent): void {
if (e.target !== this.view.domNode) {
return;
}
const focus = this.list.getFocus();
if (focus.length === 0) {
return;
}
const focusedDomElement = this.view.domElement(focus[0]);
const tabIndexElement = focusedDomElement.querySelector('[tabIndex]');
if (!tabIndexElement || !(tabIndexElement instanceof HTMLElement)) {
return;
}
e.preventDefault();
e.stopPropagation();
tabIndexElement.focus();
}
dispose() {
this.disposables = dispose(this.disposables);
}
}
export function isSelectionSingleChangeEvent(event: IListMouseEvent<any> | IListTouchEvent<any>): boolean {
return platform.isMacintosh ? event.browserEvent.metaKey : event.browserEvent.ctrlKey;
}
@@ -781,6 +826,8 @@ export class List<T> implements ISpliceable<T>, IDisposable {
this.onDidFocus = mapEvent(domEvent(this.view.domNode, 'focus', true), () => null);
this.onDidBlur = mapEvent(domEvent(this.view.domNode, 'blur', true), () => null);
this.disposables.push(new DOMFocusController(this, this.view));
if (typeof options.keyboardSupport !== 'boolean' || options.keyboardSupport) {
const controller = new KeyboardController(this, this.view, options);
this.disposables.push(controller);