Browse Source

Ensure right-side diff

main
Eric Amodio 4 years ago
parent
commit
d8c600ce53
2 changed files with 19 additions and 4 deletions
  1. +12
    -2
      src/commands/diffWithPrevious.ts
  2. +7
    -2
      src/commands/diffWithWorking.ts

+ 12
- 2
src/commands/diffWithPrevious.ts View File

@ -24,10 +24,15 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
protected preExecute(context: CommandContext, args?: DiffWithPreviousCommandArgs) {
if (context.command === Commands.DiffWithPreviousInDiffRight) {
args = { ...args };
args.inDiffRightEditor = true;
// Ensure we are on the right side -- context.uri is always the right-side uri, so ensure the editor matches, otherwise we are on the left
if (context.editor?.document.uri.toString() === context.uri?.toString()) {
args.inDiffRightEditor = true;
}
}
return this.execute(context.editor, context.uri, args);
// Always pass the editor.uri (if we have one), so we are correct for a split diff
return this.execute(context.editor, context.editor?.document.uri ?? context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithPreviousCommandArgs) {
@ -63,6 +68,11 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
gitUri = await GitUri.fromUri(uri);
}
// If we are in the right diff editor, we can't really trust the line number
// if (args.inDiffRightEditor && args.line !== 0) {
// // TODO@eamodio figure out how to tell where the line moved in the previous commit (if at all)
// }
try {
const diffUris = await Container.git.getPreviousDiffUris(
gitUri.repoPath!,

+ 7
- 2
src/commands/diffWithWorking.ts View File

@ -22,10 +22,15 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
protected preExecute(context: CommandContext, args?: DiffWithWorkingCommandArgs) {
if (context.command === Commands.DiffWithWorkingInDiffRight) {
args = { ...args };
args.inDiffRightEditor = true;
// Ensure we are on the right side -- context.uri is always the right-side uri, so ensure the editor matches, otherwise we are on the left
if (context.editor?.document.uri.toString() === context.uri?.toString()) {
args.inDiffRightEditor = true;
}
}
return this.execute(context.editor, context.uri, args);
// Always pass the editor.uri (if we have one), so we are correct for a split diff
return this.execute(context.editor, context.editor?.document.uri ?? context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithWorkingCommandArgs): Promise<any> {

Loading…
Cancel
Save