Skip to content

Commit

Permalink
fix #49, fix #2. Reveal to the line where the first commit sits on.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 24, 2018
1 parent 067ca0f commit 18c6f1d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/view/prFileChangesTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ export class PullRequestFileChangesTreeDataProvider extends vscode.Disposable im
return element;
}

if (element.comments && element.comments.length) {
element.iconPath = Resource.icons.light.Comment;
} else {
element.iconPath = Resource.getFileStatusUri(element);
}
element.resourceUri = element.filePath;
return element;
return element.getTreeItem();
}

getChildren(element?: FileChangeNode): vscode.ProviderResult<(FileChangeNode | DescriptionNode)[]> {
Expand Down
43 changes: 33 additions & 10 deletions src/view/treeNodes/fileChangeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { GitChangeType } from '../../common/file';
import { Resource } from '../../common/resources';
import { IPullRequestModel } from '../../github/interface';
import { TreeNode } from './treeNode';
import { Comment } from '../../common/comment';
import { getDiffLineByPosition } from '../../common/diffPositionMapping';

export class FileChangeNode extends TreeNode implements vscode.TreeItem {
public iconPath?: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri };
public resourceUri: vscode.Uri;
public sha: string;
public parentSha: string;
public command?: vscode.Command;
public comments?: any[];
public comments?: Comment[];
public contextValue: string;

get letter(): string {
Expand Down Expand Up @@ -49,15 +51,6 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
) {
super();
this.contextValue = 'filechange';
this.command = {
title: 'show diff',
command: 'vscode.diff',
arguments: [
this.parentFilePath,
this.filePath,
this.fileName
]
};
}

getTreeItem(): vscode.TreeItem {
Expand All @@ -67,6 +60,36 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
this.iconPath = Resource.getFileStatusUri(this);
}
this.resourceUri = this.filePath;

let opts = {};
if (this.comments && this.comments.length) {
let sortedActiveComments = this.comments.filter(comment => comment.position).sort((a, b) => {
return a.position - b.position;
});

if (sortedActiveComments.length) {
let comment = sortedActiveComments[0];
let diffLine = getDiffLineByPosition(comment.diff_hunks, comment.position === null ? comment.original_position : comment.position);

if (diffLine) {
opts = {
selection: new vscode.Range(diffLine.newLineNumber - 1, 0, diffLine.newLineNumber - 1, 0)
};
}
}
}

this.command = {
title: 'show diff',
command: 'vscode.diff',
arguments: [
this.parentFilePath,
this.filePath,
this.fileName,
opts
]
};

return this;
}

Expand Down

0 comments on commit 18c6f1d

Please sign in to comment.