Skip to content
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

Implement keyboard navigation between list find/filter matches #180078

Merged
merged 8 commits into from
Dec 19, 2023
16 changes: 8 additions & 8 deletions src/vs/base/browser/ui/tree/abstractTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { IDragAndDropData } from 'vs/base/browser/dnd';
import { $, append, clearNode, createStyleSheet, getWindow, h, hasParentWithClass, isActiveElement } from 'vs/base/browser/dom';
import { $, append, clearNode, createStyleSheet, getWindow, h, hasParentWithClass, isActiveElement, isKeyboardEvent } from 'vs/base/browser/dom';
import { DomEmitter } from 'vs/base/browser/event';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
Expand Down Expand Up @@ -1148,7 +1148,7 @@ class FindController<T, TFilterData> implements IDisposable {
}

shouldAllowFocus(node: ITreeNode<T, TFilterData>): boolean {
if (!this.widget || !this.pattern || this._mode === TreeFindMode.Filter) {
if (!this.widget || !this.pattern) {
return true;
}

Expand Down Expand Up @@ -2391,27 +2391,27 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable
this.view.setFocus(indexes, browserEvent, true);
}

focusNext(n = 1, loop = false, browserEvent?: UIEvent, filter = this.focusNavigationFilter): void {
focusNext(n = 1, loop = false, browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): void {
this.view.focusNext(n, loop, browserEvent, filter);
}

focusPrevious(n = 1, loop = false, browserEvent?: UIEvent, filter = this.focusNavigationFilter): void {
focusPrevious(n = 1, loop = false, browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): void {
this.view.focusPrevious(n, loop, browserEvent, filter);
}

focusNextPage(browserEvent?: UIEvent, filter = this.focusNavigationFilter): Promise<void> {
focusNextPage(browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): Promise<void> {
return this.view.focusNextPage(browserEvent, filter);
}

focusPreviousPage(browserEvent?: UIEvent, filter = this.focusNavigationFilter): Promise<void> {
focusPreviousPage(browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): Promise<void> {
return this.view.focusPreviousPage(browserEvent, filter);
}

focusLast(browserEvent?: UIEvent, filter = this.focusNavigationFilter): void {
focusLast(browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): void {
this.view.focusLast(browserEvent, filter);
}

focusFirst(browserEvent?: UIEvent, filter = this.focusNavigationFilter): void {
focusFirst(browserEvent?: UIEvent, filter = (isKeyboardEvent(browserEvent) && browserEvent.altKey) ? undefined : this.focusNavigationFilter): void {
this.view.focusFirst(browserEvent, filter);
}

Expand Down
60 changes: 60 additions & 0 deletions src/vs/workbench/browser/actions/listCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,40 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.focusAnyDown',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.Alt | KeyCode.DownArrow,
mac: {
primary: KeyMod.Alt | KeyCode.DownArrow,
secondary: [KeyMod.WinCtrl | KeyMod.Alt | KeyCode.KeyN]
},
handler: (accessor, arg2) => {
navigate(accessor.get(IListService).lastFocusedList, async widget => {
const fakeKeyboardEvent = new KeyboardEvent('keydown', { altKey: true });
await widget.focusNext(typeof arg2 === 'number' ? arg2 : 1, false, fakeKeyboardEvent);
});
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.focusAnyUp',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.Alt | KeyCode.UpArrow,
mac: {
primary: KeyMod.Alt | KeyCode.UpArrow,
secondary: [KeyMod.WinCtrl | KeyMod.Alt | KeyCode.KeyP]
},
handler: (accessor, arg2) => {
navigate(accessor.get(IListService).lastFocusedList, async widget => {
const fakeKeyboardEvent = new KeyboardEvent('keydown', { altKey: true });
await widget.focusPrevious(typeof arg2 === 'number' ? arg2 : 1, false, fakeKeyboardEvent);
});
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.focusPageDown',
weight: KeybindingWeight.WorkbenchContrib,
Expand Down Expand Up @@ -154,6 +188,32 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.focusAnyFirst',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.Alt | KeyCode.Home,
handler: (accessor) => {
navigate(accessor.get(IListService).lastFocusedList, async widget => {
const fakeKeyboardEvent = new KeyboardEvent('keydown', { altKey: true });
await widget.focusFirst(fakeKeyboardEvent);
});
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.focusAnyLast',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.Alt | KeyCode.End,
handler: (accessor) => {
navigate(accessor.get(IListService).lastFocusedList, async widget => {
const fakeKeyboardEvent = new KeyboardEvent('keydown', { altKey: true });
await widget.focusLast(fakeKeyboardEvent);
});
}
});

function expandMultiSelection(focused: WorkbenchListWidget, previousFocus: unknown): void {

// List
Expand Down