mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-29 17:25:20 -05:00
Adds commit navigation in quick pick lists via alt+, alt+.
Reworks keyboard context
This commit is contained in:
@@ -4,13 +4,21 @@ import { CommandContext, setCommandContext } from '../commands';
|
||||
import { CommandQuickPickItem, OpenFileCommandQuickPickItem } from '../quickPicks/quickPicks';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export declare type Keys = 'left' | 'right';
|
||||
export declare type Keys = 'left' | 'right' | ',' | '.';
|
||||
export const keys: Keys[] = [
|
||||
'left',
|
||||
'right'
|
||||
'right',
|
||||
',',
|
||||
'.'
|
||||
];
|
||||
|
||||
let scopeCount = 0;
|
||||
let counters = {
|
||||
left: 0,
|
||||
right: 0,
|
||||
',': 0,
|
||||
'.': 0
|
||||
};
|
||||
|
||||
let _instance: Keyboard;
|
||||
|
||||
@@ -41,7 +49,10 @@ export class Keyboard extends Disposable {
|
||||
}
|
||||
|
||||
async execute(key: Keys): Promise<{}> {
|
||||
const command = this.context.globalState.get(`gitlens:key:${key}`) as CommandQuickPickItem;
|
||||
let command = this.context.globalState.get(`gitlens:key:${key}`) as CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
|
||||
if (typeof command === 'function') {
|
||||
command = await command();
|
||||
}
|
||||
if (!command || !(command instanceof CommandQuickPickItem)) return undefined;
|
||||
|
||||
Logger.log('Keyboard.execute', key);
|
||||
@@ -54,11 +65,13 @@ export class Keyboard extends Disposable {
|
||||
return await command.execute();
|
||||
}
|
||||
|
||||
async enterScope(...keyCommands: [Keys, QuickPickItem][]) {
|
||||
async enterScope(...keyCommands: [Keys, QuickPickItem | (() => Promise<QuickPickItem>)][]) {
|
||||
Logger.log('Keyboard.enterScope', scopeCount);
|
||||
await setCommandContext(CommandContext.Key, ++scopeCount);
|
||||
scopeCount++;
|
||||
// await setCommandContext(CommandContext.Key, ++scopeCount);
|
||||
if (keyCommands && Array.isArray(keyCommands) && keyCommands.length) {
|
||||
for (const [key, command] of keyCommands) {
|
||||
await setCommandContext(`${CommandContext.Key}:${key}`, ++counters[key]);
|
||||
await this.setKeyCommand(key as Keys, command);
|
||||
}
|
||||
}
|
||||
@@ -66,9 +79,15 @@ export class Keyboard extends Disposable {
|
||||
|
||||
async exitScope(clear: boolean = true) {
|
||||
Logger.log('Keyboard.exitScope', scopeCount);
|
||||
await setCommandContext(CommandContext.Key, --scopeCount);
|
||||
if (scopeCount) {
|
||||
scopeCount--;
|
||||
// await setCommandContext(CommandContext.Key, --scopeCount);
|
||||
}
|
||||
if (clear && !scopeCount) {
|
||||
for (const key of keys) {
|
||||
if (counters[key]) {
|
||||
await setCommandContext(`${CommandContext.Key}:${key}`, --counters[key]);
|
||||
}
|
||||
await this.clearKeyCommand(key);
|
||||
}
|
||||
}
|
||||
@@ -76,11 +95,15 @@ export class Keyboard extends Disposable {
|
||||
|
||||
async clearKeyCommand(key: Keys) {
|
||||
Logger.log('Keyboard.clearKeyCommand', key);
|
||||
if (counters[key]) {
|
||||
await setCommandContext(`${CommandContext.Key}:${key}`, --counters[key]);
|
||||
}
|
||||
await this.context.globalState.update(`gitlens:key:${key}`, undefined);
|
||||
}
|
||||
|
||||
async setKeyCommand(key: Keys, command: QuickPickItem) {
|
||||
async setKeyCommand(key: Keys, command: QuickPickItem | (() => Promise<QuickPickItem>)) {
|
||||
Logger.log('Keyboard.setKeyCommand', key);
|
||||
await setCommandContext(`${CommandContext.Key}:${key}`, ++counters[key]);
|
||||
await this.context.globalState.update(`gitlens:key:${key}`, command);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands } from './commands';
|
||||
import { GitCommit, GitLogCommit, GitProvider, GitUri } from '../gitProvider';
|
||||
import { GitCommit, GitLogCommit, GitProvider, GitUri, IGitLog } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, CommitDetailsQuickPick, CommitWithFileStatusQuickPickItem } from '../quickPicks';
|
||||
|
||||
export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
|
||||
constructor(private git: GitProvider) {
|
||||
constructor(private git: GitProvider, private repoPath: string) {
|
||||
super(Commands.ShowQuickCommitDetails);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem) {
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem, repoLog?: IGitLog) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
if (!editor || !editor.document) return undefined;
|
||||
uri = editor.document.uri;
|
||||
@@ -45,21 +44,31 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
|
||||
try {
|
||||
if (!commit || !(commit instanceof GitLogCommit) || commit.type !== 'repo') {
|
||||
let log = await this.git.getLogForRepo(repoPath, sha, 2);
|
||||
if (!log) return window.showWarningMessage(`Unable to show commit details`);
|
||||
if (repoLog) {
|
||||
commit = repoLog.commits.get(sha);
|
||||
// If we can't find the commit, kill the repoLog
|
||||
if (!commit) {
|
||||
repoLog = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
commit = Iterables.first(log.commits.values());
|
||||
if (!repoLog) {
|
||||
const log = await this.git.getLogForRepo(repoPath || this.repoPath, sha, 2);
|
||||
if (!log) return window.showWarningMessage(`Unable to show commit details`);
|
||||
|
||||
commit = log.commits.get(sha);
|
||||
}
|
||||
}
|
||||
|
||||
if (!goBackCommand) {
|
||||
// Create a command to get back to the commit details
|
||||
// Create a command to get back to the repository history
|
||||
goBackCommand = new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to repository history`
|
||||
}, Commands.ShowQuickRepoHistory, [new GitUri(commit.uri, commit)]);
|
||||
}
|
||||
|
||||
const pick = await CommitDetailsQuickPick.show(commit as GitLogCommit, uri, goBackCommand);
|
||||
const pick = await CommitDetailsQuickPick.show(this.git, commit as GitLogCommit, uri, goBackCommand, repoLog);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (!(pick instanceof CommitWithFileStatusQuickPickItem)) {
|
||||
@@ -71,7 +80,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to details of \u00a0$(git-commit) ${pick.shortSha}`
|
||||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand]));
|
||||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand, repoLog]));
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error('[GitLens.ShowQuickCommitDetailsCommand]', ex);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands } from './commands';
|
||||
import { GitCommit, GitLogCommit, GitProvider, GitUri } from '../gitProvider';
|
||||
import { GitCommit, GitLogCommit, GitProvider, GitUri, IGitLog } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, CommitFileDetailsQuickPick } from '../quickPicks';
|
||||
import * as path from 'path';
|
||||
@@ -13,19 +12,17 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
super(Commands.ShowQuickCommitFileDetails);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }) {
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }, fileLog?: IGitLog) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
if (!editor || !editor.document) return undefined;
|
||||
uri = editor.document.uri;
|
||||
}
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
let repoPath = gitUri.repoPath;
|
||||
|
||||
if (!sha) {
|
||||
if (!editor) return undefined;
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
const blameline = editor.selection.active.line - gitUri.offset;
|
||||
if (blameline < 0) return undefined;
|
||||
|
||||
@@ -34,7 +31,6 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
if (!blame) return window.showWarningMessage(`Unable to show commit file details. File is probably not under source control`);
|
||||
|
||||
sha = blame.commit.isUncommitted ? blame.commit.previousSha : blame.commit.sha;
|
||||
repoPath = blame.commit.repoPath;
|
||||
|
||||
commit = blame.commit;
|
||||
}
|
||||
@@ -45,11 +41,21 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!commit || ((commit instanceof GitLogCommit) && commit.type !== 'file')) {
|
||||
let log = await this.git.getLogForFile(uri.fsPath, sha, undefined, undefined, 2);
|
||||
if (!log) return window.showWarningMessage(`Unable to show commit file details`);
|
||||
if (!commit || !(commit instanceof GitLogCommit) || commit.type !== 'file') {
|
||||
if (fileLog) {
|
||||
commit = fileLog.commits.get(sha);
|
||||
// If we can't find the commit, kill the fileLog
|
||||
if (!commit) {
|
||||
fileLog = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
commit = Iterables.find(log.commits.values(), c => c.sha === sha);
|
||||
if (!fileLog) {
|
||||
const log = await this.git.getLogForFile(uri.fsPath, sha, undefined, undefined, 2);
|
||||
if (!log) return window.showWarningMessage(`Unable to show commit file details`);
|
||||
|
||||
commit = log.commits.get(sha);
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to the most recent commit -- so that we can find the real working filename if there was a rename
|
||||
@@ -67,13 +73,13 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, commit]);
|
||||
}
|
||||
|
||||
const pick = await CommitFileDetailsQuickPick.show(this.git, commit, workingFileName, uri, goBackCommand,
|
||||
const pick = await CommitFileDetailsQuickPick.show(this.git, commit as GitLogCommit, workingFileName, uri, goBackCommand,
|
||||
// Create a command to get back to where we are right now
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to details of \u00a0$(file-text) ${path.basename(commit.fileName)} in \u00a0$(git-commit) ${shortSha}`
|
||||
}, Commands.ShowQuickCommitFileDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand, options]),
|
||||
{ showFileHistory: options.showFileHistory });
|
||||
{ showFileHistory: options.showFileHistory }, fileLog);
|
||||
|
||||
if (!pick) return undefined;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands } from './commands';
|
||||
import { GitProvider, GitUri } from '../gitProvider';
|
||||
import { GitProvider, GitUri, IGitLog } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
|
||||
import * as path from 'path';
|
||||
@@ -12,7 +12,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
||||
super(Commands.ShowQuickFileHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
|
||||
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
uri = editor && editor.document && editor.document.uri;
|
||||
}
|
||||
@@ -28,10 +28,12 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
||||
if (!log) {
|
||||
log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
||||
}
|
||||
|
||||
let pick = await FileHistoryQuickPick.show(log, uri, gitUri.sha, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||
const pick = await FileHistoryQuickPick.show(log, uri, gitUri.sha, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (pick instanceof CommandQuickPickItem) {
|
||||
@@ -42,8 +44,9 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(pick.commit.fileName)}`
|
||||
}, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand]),
|
||||
{ showFileHistory: false });
|
||||
}, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand, log]),
|
||||
{ showFileHistory: false },
|
||||
log);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands } from './commands';
|
||||
import { GitProvider, GitUri } from '../gitProvider';
|
||||
import { GitProvider, GitUri, IGitLog } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, RepoHistoryQuickPick } from '../quickPicks';
|
||||
|
||||
@@ -11,7 +11,7 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
super(Commands.ShowQuickRepoHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
|
||||
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
uri = editor && editor.document && editor.document.uri;
|
||||
}
|
||||
@@ -21,11 +21,13 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath);
|
||||
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
||||
if (!log) {
|
||||
const repoPath = await this.git.getRepoPathFromUri(uri, this.repoPath);
|
||||
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
||||
|
||||
const log = await this.git.getLogForRepo(repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
||||
log = await this.git.getLogForRepo(repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
||||
}
|
||||
|
||||
const pick = await RepoHistoryQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||
if (!pick) return undefined;
|
||||
@@ -38,7 +40,8 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to repository history`
|
||||
}, Commands.ShowQuickRepoHistory, [uri, maxCount, goBackCommand]));
|
||||
}, Commands.ShowQuickRepoHistory, [uri, maxCount, goBackCommand, log]),
|
||||
log);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', ex);
|
||||
|
||||
Reference in New Issue
Block a user