提交 7d840a33 编写于 作者: B Benjamin Pasero

more list/tree commands (for #11517)

上级 7a5b24d3
......@@ -139,6 +139,8 @@ export class DefaultController implements _.IController {
this.options = options;
this.downKeyBindingDispatcher = new KeybindingDispatcher();
this.upKeyBindingDispatcher = new KeybindingDispatcher();
if (typeof options.keyboardSupport !== 'boolean' || options.keyboardSupport) {
this.downKeyBindingDispatcher.set(KeyCode.UpArrow, (t, e) => this.onUp(t, e));
this.downKeyBindingDispatcher.set(KeyCode.DownArrow, (t, e) => this.onDown(t, e));
......@@ -147,19 +149,17 @@ export class DefaultController implements _.IController {
if (platform.isMacintosh) {
this.downKeyBindingDispatcher.set(KeyMod.CtrlCmd | KeyCode.UpArrow, (t, e) => this.onLeft(t, e));
}
}
this.downKeyBindingDispatcher.set(KeyCode.PageUp, (t, e) => this.onPageUp(t, e));
this.downKeyBindingDispatcher.set(KeyCode.PageDown, (t, e) => this.onPageDown(t, e));
this.downKeyBindingDispatcher.set(KeyCode.Home, (t, e) => this.onHome(t, e));
this.downKeyBindingDispatcher.set(KeyCode.End, (t, e) => this.onEnd(t, e));
// TODO@Ben adopt more keybindings as configurable commands
this.downKeyBindingDispatcher.set(KeyCode.Space, (t, e) => this.onSpace(t, e));
this.downKeyBindingDispatcher.set(KeyCode.PageUp, (t, e) => this.onPageUp(t, e));
this.downKeyBindingDispatcher.set(KeyCode.PageDown, (t, e) => this.onPageDown(t, e));
this.downKeyBindingDispatcher.set(KeyCode.Escape, (t, e) => this.onEscape(t, e));
this.downKeyBindingDispatcher.set(KeyCode.Home, (t, e) => this.onHome(t, e));
this.downKeyBindingDispatcher.set(KeyCode.End, (t, e) => this.onEnd(t, e));
this.downKeyBindingDispatcher.set(KeyCode.Space, (t, e) => this.onSpace(t, e));
this.downKeyBindingDispatcher.set(KeyCode.Escape, (t, e) => this.onEscape(t, e));
this.upKeyBindingDispatcher = new KeybindingDispatcher();
this.upKeyBindingDispatcher.set(KeyCode.Enter, this.onEnter.bind(this));
this.upKeyBindingDispatcher.set(KeyMod.CtrlCmd | KeyCode.Enter, this.onEnter.bind(this));
this.upKeyBindingDispatcher.set(KeyCode.Enter, this.onEnter.bind(this));
this.upKeyBindingDispatcher.set(KeyMod.CtrlCmd | KeyCode.Enter, this.onEnter.bind(this));
}
}
public onMouseDown(tree: _.ITree, element: any, event: mouse.IMouseEvent, origin: string = 'mouse'): boolean {
......
......@@ -90,7 +90,7 @@ export function registerCommands(): void {
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.left',
id: 'list.collapse',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.LeftArrow,
......@@ -121,7 +121,7 @@ export function registerCommands(): void {
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.right',
id: 'list.expand',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.RightArrow,
......@@ -147,6 +147,176 @@ export function registerCommands(): void {
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.pageUp',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.PageUp,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// List
if (focused instanceof List) {
const list = focused;
list.focusPreviousPage();
list.reveal(list.getFocus()[0]);
}
// Tree
else if (focused) {
const tree = focused;
tree.focusPreviousPage({ origin: 'keyboard' });
tree.reveal(tree.getFocus()).done(null, errors.onUnexpectedError);
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.pageDown',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.PageDown,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// List
if (focused instanceof List) {
const list = focused;
list.focusNextPage();
list.reveal(list.getFocus()[0]);
}
// Tree
else if (focused) {
const tree = focused;
tree.focusNextPage({ origin: 'keyboard' });
tree.reveal(tree.getFocus()).done(null, errors.onUnexpectedError);
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.first',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.Home,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// Tree only
if (!(focused instanceof List)) {
const tree = focused;
tree.focusFirst({ origin: 'keyboard' });
tree.reveal(tree.getFocus()).done(null, errors.onUnexpectedError);
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.last',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.End,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// Tree only
if (!(focused instanceof List)) {
const tree = focused;
tree.focusLast({ origin: 'keyboard' });
tree.reveal(tree.getFocus()).done(null, errors.onUnexpectedError);
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.select',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.Enter,
secondary: [KeyMod.CtrlCmd | KeyCode.Enter],
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// List
if (focused instanceof List) {
const list = focused;
list.setSelection(list.getFocus());
}
// Tree
else if (focused) {
const tree = focused;
const focus = tree.getFocus();
if (focus) {
tree.setSelection([focus], { origin: 'keyboard' });
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.toggleExpand',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.Space,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// Tree only
if (!(focused instanceof List)) {
const tree = focused;
const focus = tree.getFocus();
if (focus) {
tree.toggleExpansion(focus);
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.clear',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ListFocusContext,
primary: KeyCode.Escape,
handler: (accessor) => {
const listService = accessor.get(IListService);
const focused = listService.getFocused();
// Tree only
if (!(focused instanceof List)) {
const tree = focused;
if (tree.getSelection().length) {
tree.clearSelection({ origin: 'keyboard' });
return void 0;
}
if (tree.getFocus()) {
tree.clearFocus({ origin: 'keyboard' });
return void 0;
}
}
}
});
// --- commands
KeybindingsRegistry.registerCommandAndKeybindingRule({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册