Browse Source

Adds keyboard nav support to Git commands

Adds left arrow to go back if there is no text value
main
Eric Amodio 5 years ago
parent
commit
5b7729870e
2 changed files with 59 additions and 5 deletions
  1. +56
    -5
      src/commands/gitCommands.ts
  2. +3
    -0
      src/commands/quickCommand.ts

+ 56
- 5
src/commands/gitCommands.ts View File

@ -132,7 +132,30 @@ export class GitCommandsCommand extends Command {
try {
return await new Promise<QuickPickStep | QuickInputStep | undefined>(resolve => {
const goBack = async () => {
input.value = '';
if (commandsStep.command !== undefined) {
input.busy = true;
resolve((await commandsStep.command.previous()) || commandsStep);
}
};
const scope = Container.keyboard.createScope({
left: { onDidPressKey: goBack },
right: {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(input, key)
},
'ctrl+right': {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(input, key)
},
'alt+right': {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(input, key)
}
});
scope.start();
disposables.push(
scope,
input.onDidHide(() => resolve()),
input.onDidTriggerButton(async e => {
if (e === QuickInputButtons.Back) {
@ -203,17 +226,36 @@ export class GitCommandsCommand extends Command {
try {
return await new Promise<QuickPickStep | QuickInputStep | undefined>(resolve => {
const goBack = async () => {
quickpick.value = '';
if (commandsStep.command !== undefined) {
quickpick.busy = true;
resolve((await commandsStep.command.previous()) || commandsStep);
}
};
const scope = Container.keyboard.createScope({
left: { onDidPressKey: goBack },
right: {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(quickpick, key)
},
'ctrl+right': {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(quickpick, key)
},
'alt+right': {
onDidPressKey: key => step.onDidPressKey && step.onDidPressKey(quickpick, key)
}
});
scope.start();
let overrideItems = false;
disposables.push(
scope,
quickpick.onDidHide(() => resolve()),
quickpick.onDidTriggerButton(async e => {
if (e === QuickInputButtons.Back) {
quickpick.value = '';
if (commandsStep.command !== undefined) {
quickpick.busy = true;
resolve((await commandsStep.command.previous()) || commandsStep);
}
goBack();
return;
}
@ -250,6 +292,15 @@ export class GitCommandsCommand extends Command {
}
}),
quickpick.onDidChangeValue(async e => {
if (scope !== undefined) {
// Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly
if (e.length !== 0) {
await scope.pause(['left', 'right']);
} else {
await scope.resume();
}
}
if (step.onDidChangeValue !== undefined) {
const cancel = await step.onDidChangeValue(quickpick);
if (cancel) return;

+ 3
- 0
src/commands/quickCommand.ts View File

@ -2,6 +2,7 @@
import { InputBox, QuickInputButton, QuickPick, QuickPickItem } from 'vscode';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { Container } from '../container';
import { Keys } from '../keyboard';
export * from './quickCommand.helpers';
@ -19,6 +20,7 @@ export interface QuickInputStep {
value?: string;
onDidClickButton?(input: InputBox, button: QuickInputButton): void;
onDidPressKey?(quickpick: InputBox, key: Keys): void | Promise<void>;
validate?(value: string | undefined): [boolean, string | undefined] | Promise<[boolean, string | undefined]>;
}
@ -41,6 +43,7 @@ export interface QuickPickStep {
onDidAccept?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidChangeValue?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidClickButton?(quickpick: QuickPick<T>, button: QuickInputButton): void;
onDidPressKey?(quickpick: QuickPick<T>, key: Keys): void | Promise<void>;
onValidateValue?(quickpick: QuickPick<T>, value: string, items: T[]): boolean | Promise<boolean>;
validate?(selection: T[]): boolean;
}

Loading…
Cancel
Save