Skip to content

Commit 0e33830

Browse files
committed
Fixes jumpiness when opening a diff
1 parent e39bd5d commit 0e33830

File tree

7 files changed

+49
-34
lines changed

7 files changed

+49
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1818
- Removes unneeded `gitlens.stashExplorer.enabled` configuration setting since users can add or remove custom views natively now
1919
- Removes unneeded `Toggle Git Stashed Explorer` command (`gitlens.stashExplorer.toggle`) since users can add or remove custom views natively now
2020

21+
## Fixed
22+
- Fixes jumpiness when opening a diff to a certain line
23+
2124
## [4.3.3] - 2017-07-28
2225
## Added
2326
- Adds progress indicator for when computing annotations takes a while

src/commands/diffLineWithPrevious.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
2+
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
44
import { BuiltInCommands, GlyphChars } from '../constants';
55
import { DiffWithPreviousCommandArgs } from './diffWithPrevious';
@@ -77,16 +77,18 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
7777
this.git.getVersionedFile(args.commit.repoPath, args.commit.uri.fsPath, args.commit.sha)
7878
]);
7979

80+
if (args.line !== undefined && args.line !== 0) {
81+
if (args.showOptions === undefined) {
82+
args.showOptions = {};
83+
}
84+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
85+
}
86+
8087
await commands.executeCommand(BuiltInCommands.Diff,
8188
Uri.file(lhs),
8289
Uri.file(rhs),
8390
`${path.basename(args.commit.uri.fsPath)} (${args.commit.shortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(gitUri.fsPath)} (${gitUri.shortSha})`,
8491
args.showOptions);
85-
86-
if (args.line === undefined || args.line === 0) return undefined;
87-
88-
// TODO: Figure out how to focus the left pane
89-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
9092
}
9193
catch (ex) {
9294
Logger.error(ex, 'DiffWithPreviousLineCommand', 'getVersionedFile');

src/commands/diffWithBranch.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
2+
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
44
import { BuiltInCommands, GlyphChars } from '../constants';
55
import { GitService, GitUri } from '../gitService';
@@ -45,16 +45,18 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
4545
try {
4646
const compare = await this.git.getVersionedFile(gitUri.repoPath, gitUri.fsPath, branch);
4747

48+
if (args.line !== undefined && args.line !== 0) {
49+
if (args.showOptions === undefined) {
50+
args.showOptions = {};
51+
}
52+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
53+
}
54+
4855
await commands.executeCommand(BuiltInCommands.Diff,
4956
Uri.file(compare),
5057
gitUri.fileUri(),
5158
`${path.basename(gitUri.fsPath)} (${branch}) ${GlyphChars.ArrowLeftRight} ${path.basename(gitUri.fsPath)}`,
5259
args.showOptions);
53-
54-
if (args.line === undefined || args.line === 0) return undefined;
55-
56-
// TODO: Figure out how to focus the left pane
57-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
5860
}
5961
catch (ex) {
6062
Logger.error(ex, 'DiffWithBranchCommand', 'getVersionedFile');

src/commands/diffWithNext.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
6060
this.git.getVersionedFile(args.commit.repoPath, args.commit.uri.fsPath, args.commit.sha)
6161
]);
6262

63+
if (args.line !== undefined && args.line !== 0) {
64+
if (args.showOptions === undefined) {
65+
args.showOptions = {};
66+
}
67+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
68+
}
69+
6370
await commands.executeCommand(BuiltInCommands.Diff,
6471
Uri.file(lhs),
6572
Uri.file(rhs),
6673
`${path.basename(args.commit.uri.fsPath)} (${args.commit.shortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(args.commit.nextUri.fsPath)} (${args.commit.nextShortSha})`,
6774
args.showOptions);
68-
69-
if (args.line === undefined || args.line === 0) return undefined;
70-
71-
// TODO: Figure out how to focus the left pane
72-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
7375
}
7476
catch (ex) {
7577
Logger.error(ex, 'DiffWithNextCommand', 'getVersionedFile');

src/commands/diffWithPrevious.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
5959
this.git.getVersionedFile(args.commit.repoPath, args.commit.previousUri.fsPath, args.commit.previousSha)
6060
]);
6161

62+
if (args.line !== undefined && args.line !== 0) {
63+
if (args.showOptions === undefined) {
64+
args.showOptions = {};
65+
}
66+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
67+
}
68+
6269
await commands.executeCommand(BuiltInCommands.Diff,
6370
Uri.file(lhs),
6471
Uri.file(rhs),
6572
`${path.basename(args.commit.previousUri.fsPath)} (${args.commit.previousShortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(args.commit.uri.fsPath)} (${args.commit.shortSha})`,
6673
args.showOptions);
67-
68-
if (args.line === undefined || args.line === 0) return undefined;
69-
70-
// TODO: Figure out how to focus the left pane
71-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
7274
}
7375
catch (ex) {
7476
Logger.error(ex, 'DiffWithPreviousCommand', 'getVersionedFile');

src/commands/diffWithRevision.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
2+
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
44
import { BuiltInCommands, GlyphChars } from '../constants';
55
import { GitService, GitUri } from '../gitService';
@@ -48,16 +48,18 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
4848

4949
const compare = await this.git.getVersionedFile(gitUri.repoPath, gitUri.fsPath, pick.commit.sha);
5050

51+
if (args.line !== undefined && args.line !== 0) {
52+
if (args.showOptions === undefined) {
53+
args.showOptions = {};
54+
}
55+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
56+
}
57+
5158
await commands.executeCommand(BuiltInCommands.Diff,
5259
Uri.file(compare),
5360
gitUri.fileUri(),
5461
`${path.basename(gitUri.fsPath)} (${pick.commit.shortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(gitUri.fsPath)}`,
5562
args.showOptions);
56-
57-
if (args.line === undefined || args.line === 0) return undefined;
58-
59-
// TODO: Figure out how to focus the left pane
60-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
6163
}
6264
catch (ex) {
6365
Logger.error(ex, 'DiffWithRevisionCommand', 'getVersionedFile');

src/commands/diffWithWorking.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
2+
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
44
import { BuiltInCommands, GlyphChars } from '../constants';
55
import { GitCommit, GitService, GitUri } from '../gitService';
@@ -51,16 +51,18 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
5151
try {
5252
const compare = await this.git.getVersionedFile(args.commit.repoPath, args.commit.uri.fsPath, args.commit.sha);
5353

54+
if (args.line !== undefined && args.line !== 0) {
55+
if (args.showOptions === undefined) {
56+
args.showOptions = {};
57+
}
58+
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
59+
}
60+
5461
await commands.executeCommand(BuiltInCommands.Diff,
5562
Uri.file(compare),
5663
Uri.file(path.resolve(gitUri.repoPath, workingFileName)),
5764
`${path.basename(args.commit.uri.fsPath)} (${args.commit.shortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(workingFileName)}`,
5865
args.showOptions);
59-
60-
if (args.line === undefined || args.line === 0) return undefined;
61-
62-
// TODO: Figure out how to focus the left pane
63-
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: args.line, at: 'center' });
6466
}
6567
catch (ex) {
6668
Logger.error(ex, 'DiffWithWorkingCommand', 'getVersionedFile');

0 commit comments

Comments
 (0)