mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-27 17:25:09 -05:00
Adds paging support to repo/file quick picks
Adds keyboard support to page in repo/file quick picks Adds progress indicator for repo/file quick picks Completely reworks keyboard scopes
This commit is contained in:
@@ -1,40 +1,66 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { CancellationTokenSource, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard } from '../commands';
|
||||
import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
|
||||
import { GitUri, IGitLog } from '../gitProvider';
|
||||
import { CommitQuickPickItem } from './gitQuickPicks';
|
||||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
|
||||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './quickPicks';
|
||||
import * as path from 'path';
|
||||
|
||||
export class FileHistoryQuickPick {
|
||||
|
||||
static async show(log: IGitLog, uri: Uri, sha: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
static showProgress(maxCount?: number) {
|
||||
return showQuickPickProgress(`Loading file history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
|
||||
{
|
||||
left: KeyNoopCommand,
|
||||
',': KeyNoopCommand,
|
||||
'.': KeyNoopCommand
|
||||
});
|
||||
}
|
||||
|
||||
static async show(log: IGitLog, uri: GitUri, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
|
||||
|
||||
if (log.truncated) {
|
||||
let previousPageCommand: CommandQuickPickItem;
|
||||
|
||||
let index = 0;
|
||||
if (log.truncated || uri.sha) {
|
||||
index++;
|
||||
items.splice(0, 0, new CommandQuickPickItem({
|
||||
label: `$(sync) Show All Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${log.maxCount} commits`,
|
||||
detail: `This may take a while`
|
||||
}, Commands.ShowQuickFileHistory, [uri, 0, goBackCommand]));
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
|
||||
}, Commands.ShowQuickFileHistory, [Uri.file(uri.fsPath), 0, goBackCommand]));
|
||||
|
||||
const last = Iterables.last(log.commits.values());
|
||||
items.push(new CommandQuickPickItem({
|
||||
label: `$(ellipsis) Show More Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Shows the next ${log.maxCount} commits`
|
||||
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand]));
|
||||
if (nextPageCommand) {
|
||||
index++;
|
||||
items.splice(0, 0, nextPageCommand);
|
||||
}
|
||||
|
||||
if (log.truncated) {
|
||||
const npc = new CommandQuickPickItem({
|
||||
label: `$(arrow-right) Show Next Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits`
|
||||
}, Commands.ShowQuickFileHistory, [uri, log.maxCount, goBackCommand, undefined, nextPageCommand]);
|
||||
|
||||
const last = Iterables.last(log.commits.values());
|
||||
|
||||
previousPageCommand = new CommandQuickPickItem({
|
||||
label: `$(arrow-left) Show Previous Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
|
||||
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand, undefined, npc]);
|
||||
|
||||
index++;
|
||||
items.splice(0, 0, previousPageCommand);
|
||||
}
|
||||
}
|
||||
|
||||
// Only show the full repo option if we are the root
|
||||
if (!goBackCommand) {
|
||||
items.splice(0, 0, new CommandQuickPickItem({
|
||||
items.splice(index, 0, new CommandQuickPickItem({
|
||||
label: `$(repo) Show Repository History`,
|
||||
description: null,
|
||||
detail: 'Shows the commit history of the repository'
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows the repository commit history`
|
||||
}, Commands.ShowQuickRepoHistory,
|
||||
[
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
new CommandQuickPickItem({
|
||||
@@ -50,7 +76,11 @@ export class FileHistoryQuickPick {
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
await Keyboard.instance.enterScope(['left', goBackCommand]);
|
||||
const scope = await Keyboard.instance.beginScope({
|
||||
left: goBackCommand,
|
||||
',': previousPageCommand,
|
||||
'.': nextPageCommand
|
||||
});
|
||||
|
||||
const commit = Iterables.first(log.commits.values());
|
||||
|
||||
@@ -59,14 +89,14 @@ export class FileHistoryQuickPick {
|
||||
const pick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
placeHolder: `${commit.getFormattedPath()}${sha ? ` \u00a0\u2022\u00a0 ${sha.substring(0, 8)}` : ''}`,
|
||||
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
|
||||
onDidSelectItem: (item: QuickPickItem) => {
|
||||
Keyboard.instance.setKeyCommand('right', item);
|
||||
}
|
||||
placeHolder: `${commit.getFormattedPath()}${uri.sha ? ` \u00a0\u2022\u00a0 ${uri.sha.substring(0, 8)}` : ''}`,
|
||||
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||
// onDidSelectItem: (item: QuickPickItem) => {
|
||||
// scope.setKeyCommand('right', item);
|
||||
// }
|
||||
} as QuickPickOptions);
|
||||
|
||||
await Keyboard.instance.exitScope();
|
||||
await scope.dispose();
|
||||
|
||||
return pick;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user