diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index bd50225..73a7837 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -3,6 +3,7 @@ import { Iterables } from '../system'; import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand, Commands, getCommandUri } from './common'; import { BuiltInCommands } from '../constants'; +import { DiffWithWorkingCommandArgs } from './diffWithWorking'; import { GitCommit, GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; import * as moment from 'moment'; @@ -27,13 +28,13 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { args.line = args.line || (editor === undefined ? 0 : editor.selection.active.line); - if (args.commit === undefined || args.range !== undefined) { + if (args.commit === undefined || (args.commit.type !== 'file') || args.range !== undefined) { const gitUri = await GitUri.fromUri(uri, this.git); try { // If the sha is missing or the file is uncommitted, treat it as a DiffWithWorking if (gitUri.sha === undefined && await this.git.isFileUncommitted(gitUri)) { - return commands.executeCommand(Commands.DiffWithWorking, uri); + return commands.executeCommand(Commands.DiffWithWorking, uri, { showOptions: args.showOptions } as DiffWithWorkingCommandArgs); } const sha = args.commit === undefined ? gitUri.sha : args.commit.sha; diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index e974900..f815596 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -1,7 +1,7 @@ 'use strict'; import { Uri } from 'vscode'; import { DocumentSchemes } from '../constants'; -import { GitCommit, GitService, IGitStatusFile } from '../gitService'; +import { GitService, IGitStatusFile } from '../gitService'; import * as path from 'path'; export class GitUri extends Uri { @@ -93,9 +93,9 @@ export class GitUri extends Uri { } static fromFileStatus(status: IGitStatusFile, repoPath: string, original?: boolean): GitUri; - static fromFileStatus(status: IGitStatusFile, commit: GitCommit, original?: boolean): GitUri; - static fromFileStatus(status: IGitStatusFile, repoPathOrCommit: string | GitCommit, original: boolean = false): GitUri { - const repoPath = repoPathOrCommit instanceof GitCommit ? repoPathOrCommit.repoPath : repoPathOrCommit; + static fromFileStatus(status: IGitStatusFile, commit: IGitCommitInfo, original?: boolean): GitUri; + static fromFileStatus(status: IGitStatusFile, repoPathOrCommit: string | IGitCommitInfo, original: boolean = false): GitUri { + const repoPath = typeof repoPathOrCommit === 'string' ? repoPathOrCommit : repoPathOrCommit.repoPath; const uri = Uri.file(path.resolve(repoPath, original ? status.originalFileName || status.fileName : status.fileName)); return new GitUri(uri, repoPathOrCommit); } diff --git a/src/gitService.ts b/src/gitService.ts index ee69485..5e1852b 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -5,7 +5,7 @@ import { CommandContext, setCommandContext } from './commands'; import { CodeLensVisibility, IConfig } from './configuration'; import { DocumentSchemes, ExtensionKey } from './constants'; import { Git, GitBlameParser, GitBranch, GitCommit, GitLogCommit, GitLogParser, GitRemote, GitStashParser, GitStatusFile, GitStatusParser, IGit, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStash, IGitStatus } from './git/git'; -import { IGitUriData, GitUri } from './git/gitUri'; +import { GitUri, IGitCommitInfo, IGitUriData } from './git/gitUri'; import { GitCodeLensProvider } from './gitCodeLensProvider'; import { Logger } from './logger'; import * as fs from 'fs'; @@ -13,7 +13,7 @@ import * as ignore from 'ignore'; import * as moment from 'moment'; import * as path from 'path'; -export { GitUri }; +export { GitUri, IGitCommitInfo }; export * from './git/models/models'; export { getNameFromRemoteResource, RemoteResource, RemoteProvider } from './git/remotes/provider'; export * from './git/gitContextTracker'; diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index 2a491b5..0d3fbfa 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -1,15 +1,16 @@ 'use strict'; import { Arrays, Iterables } from '../system'; -import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode'; -import { Commands, CopyMessageToClipboardCommandArgs, CopyShaToClipboardCommandArgs, DiffDirectoryCommandCommandArgs, Keyboard, KeyNoopCommand, ShowQuickCommitDetailsCommandArgs, StashApplyCommandArgs, StashDeleteCommandArgs } from '../commands'; -import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './common'; -import { getGitStatusIcon, GitCommit, GitLogCommit, GitService, GitStashCommit, GitStatusFileStatus, GitUri, IGitLog, IGitStatusFile, RemoteResource } from '../gitService'; +import { commands, QuickPickOptions, TextDocumentShowOptions, Uri, window } from 'vscode'; +import { Commands, CopyMessageToClipboardCommandArgs, CopyShaToClipboardCommandArgs, DiffDirectoryCommandCommandArgs, DiffWithPreviousCommandArgs, Keyboard, KeyNoopCommand, Keys, ShowQuickCommitDetailsCommandArgs, StashApplyCommandArgs, StashDeleteCommandArgs } from '../commands'; +import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem, QuickPickItem } from './common'; +import { getGitStatusIcon, GitCommit, GitLogCommit, GitService, GitStashCommit, GitStatusFileStatus, GitUri, IGitCommitInfo, IGitLog, IGitStatusFile, RemoteResource } from '../gitService'; import { OpenRemotesCommandQuickPickItem } from './remotes'; import * as moment from 'moment'; import * as path from 'path'; export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickItem { + private commit: GitCommit; fileName: string; gitUri: GitUri; sha: string; @@ -44,12 +45,32 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI description: description }); + this.commit = commit; this.fileName = status.fileName; - this.gitUri = GitUri.fromFileStatus(status, commit.repoPath); + this.gitUri = GitUri.fromFileStatus(status, { + fileName: status.fileName, + repoPath: commit.repoPath, + sha: commit.sha, + originalFileName: status.originalFileName + } as IGitCommitInfo); this.sha = sha; this.shortSha = shortSha; this.status = status.status; } + + onDidPressKey(key: Keys): Promise<{} | undefined> { + if (this.commit.previousSha === undefined) return super.onDidPressKey(key); + + return commands.executeCommand(Commands.DiffWithPrevious, + this.gitUri, + { + commit: this.commit, + showOptions: { + preserveFocus: true, + preview: false + } as TextDocumentShowOptions + } as DiffWithPreviousCommandArgs) as Promise<{} | undefined>; + } } export class OpenCommitFilesCommandQuickPickItem extends OpenFilesCommandQuickPickItem { @@ -288,6 +309,9 @@ export class CommitDetailsQuickPick { ignoreFocusOut: getQuickPickIgnoreFocusOut(), onDidSelectItem: (item: QuickPickItem) => { scope.setKeyCommand('right', item); + if (typeof item.onDidSelect === 'function') { + item.onDidSelect(); + } } } as QuickPickOptions); diff --git a/src/quickPicks/common.ts b/src/quickPicks/common.ts index 204d658..ef15b16 100644 --- a/src/quickPicks/common.ts +++ b/src/quickPicks/common.ts @@ -120,12 +120,12 @@ export class OpenFileCommandQuickPickItem extends CommandQuickPickItem { return openEditor(this.uri, options); } - onDidSelect(): Promise<{} | undefined> { - return this.execute({ - preserveFocus: true, - preview: true - }); - } + // onDidSelect(): Promise<{} | undefined> { + // return this.execute({ + // preserveFocus: true, + // preview: true + // }); + // } onDidPressKey(key: Keys): Promise<{} | undefined> { return this.execute({ diff --git a/src/quickPicks/repoStatus.ts b/src/quickPicks/repoStatus.ts index bde7640..724616e 100644 --- a/src/quickPicks/repoStatus.ts +++ b/src/quickPicks/repoStatus.ts @@ -1,8 +1,8 @@ 'use strict'; import { Iterables } from '../system'; -import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode'; -import { Commands, Keyboard, OpenChangedFilesCommandArgs, ShowQuickBranchHistoryCommandArgs, ShowQuickRepoStatusCommandArgs, ShowQuickStashListCommandArgs } from '../commands'; -import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem } from './common'; +import { commands, QuickPickOptions, TextDocumentShowOptions, Uri, window } from 'vscode'; +import { Commands, DiffWithWorkingCommandArgs, Keyboard, Keys, OpenChangedFilesCommandArgs, ShowQuickBranchHistoryCommandArgs, ShowQuickRepoStatusCommandArgs, ShowQuickStashListCommandArgs } from '../commands'; +import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem, QuickPickItem } from './common'; import { GitService, GitStatusFile, GitUri, IGitStatus } from '../gitService'; import * as path from 'path'; @@ -25,6 +25,17 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick description: description }); } + + onDidPressKey(key: Keys): Promise<{} | undefined> { + return commands.executeCommand(Commands.DiffWithWorking, + this.uri, + { + showOptions: { + preserveFocus: true, + preview: false + } as TextDocumentShowOptions + } as DiffWithWorkingCommandArgs) as Promise<{} | undefined>; + } } export class OpenStatusFilesCommandQuickPickItem extends CommandQuickPickItem {