fix(splitview): up/down arrows should change focus between pane view headers

Closes: #117440
This commit is contained in:
João Moreno 2021-11-08 14:21:16 +01:00
parent 0600ecc75b
commit 6f0346f2cb
No known key found for this signature in database
GPG key ID: 896B853774D1A575
2 changed files with 38 additions and 1 deletions

View file

@ -79,5 +79,5 @@
},
"typescript.tsc.autoDetect": "off",
"testing.autoRun.mode": "rerun",
"conventionalCommits.scopes": ["tree", "scm", "grid"]
"conventionalCommits.scopes": ["tree", "scm", "grid", "splitview"]
}

View file

@ -457,6 +457,17 @@ export class PaneView extends Disposable {
this.onDidSashReset = this.splitview.onDidSashReset;
this.onDidSashChange = this.splitview.onDidSashChange;
this.onDidScroll = this.splitview.onDidScroll;
const onKeyDown = this._register(new DomEmitter(this.element, 'keydown'));
const onHeaderKeyDown = Event.chain(onKeyDown.event)
.filter(e => e.target instanceof HTMLElement && e.target.classList.contains('pane-header'))
.map(e => new StandardKeyboardEvent(e));
this._register(onHeaderKeyDown.filter(e => e.keyCode === KeyCode.UpArrow)
.event(() => this.focusPrevious()));
this._register(onHeaderKeyDown.filter(e => e.keyCode === KeyCode.DownArrow)
.event(() => this.focusNext()));
}
addPane(pane: Pane, size: number, index = this.splitview.length): void {
@ -572,6 +583,32 @@ export class PaneView extends Disposable {
}, 200);
}
private getPaneHeaderElements(): HTMLElement[] {
return [...this.element.querySelectorAll('.pane-header')] as HTMLElement[];
}
private focusPrevious(): void {
const headers = this.getPaneHeaderElements();
const index = headers.indexOf(document.activeElement as HTMLElement);
if (index === -1) {
return;
}
headers[Math.max(index - 1, 0)].focus();
}
private focusNext(): void {
const headers = this.getPaneHeaderElements();
const index = headers.indexOf(document.activeElement as HTMLElement);
if (index === -1) {
return;
}
headers[Math.min(index + 1, headers.length - 1)].focus();
}
override dispose(): void {
super.dispose();