提交 f32bea55 编写于 作者: R Rachel Macfarlane

Fix reply command for first comment in thread

上级 35704719
......@@ -171,7 +171,7 @@ export class PRProvider implements vscode.TreeDataProvider<PRGroupTreeItem | Pul
const _onDidChangeCommentThreads = new vscode.EventEmitter<vscode.CommentThreadChangedEvent>();
vscode.workspace.registerDocumentCommentProvider({
onDidChangeCommentThreads: _onDidChangeCommentThreads.event,
provideDocumentComments: async (document: vscode.TextDocument, token: vscode.CancellationToken) => {
provideDocumentComments: async (document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.CommentInfo> => {
if (document.uri.scheme === 'pr') {
let params = JSON.parse(document.uri.query);
let fileChange = richContentChanges.find(change => change.fileName === params.fileName);
......@@ -196,7 +196,7 @@ export class PRProvider implements vscode.TreeDataProvider<PRGroupTreeItem | Pul
return {
threads: [],
commentingRanges,
reply: reply
postReviewComment: reply
};
}
......@@ -236,7 +236,7 @@ export class PRProvider implements vscode.TreeDataProvider<PRGroupTreeItem | Pul
return {
threads,
commentingRanges,
reply: reply
postReviewComment: reply
};
}
......
......@@ -392,7 +392,7 @@ export class ReviewManager implements vscode.DecorationProvider {
private registerCommentProvider() {
this._documentCommentProvider = vscode.workspace.registerDocumentCommentProvider({
onDidChangeCommentThreads: this._onDidChangeCommentThreads.event,
provideDocumentComments: async (document: vscode.TextDocument, token: vscode.CancellationToken) => {
provideDocumentComments: async (document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.CommentInfo> => {
let ranges: vscode.Range[] = [];
let matchingComments: Comment[];
......@@ -450,7 +450,7 @@ export class ReviewManager implements vscode.DecorationProvider {
return {
threads: this.commentsToCommentThreads(matchingComments, document.uri.scheme === 'file' ? vscode.CommentThreadCollapsibleState.Collapsed : vscode.CommentThreadCollapsibleState.Expanded),
commentingRanges: ranges,
reply: this._reply
postReviewComment: this._reply
};
}
});
......
......@@ -13,6 +13,7 @@ export class CommentGlyphWidget implements IContentWidget {
private _editor: ICodeEditor;
constructor(id: string, editor: ICodeEditor, lineNumber: number, onClick: () => void) {
this._id = id;
this._domNode = document.createElement('div');
this._domNode.className = 'new-comment-hint';
this._domNode.addEventListener('click', onClick);
......
......@@ -158,6 +158,7 @@ export class ReviewZoneWidget extends ZoneWidget {
this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => {
if (this._isCollapsed) {
this._isCollapsed = false;
this.show({ lineNumber: this._commentThread.range.startLineNumber, column: 1 }, 2);
}
else {
this._isCollapsed = true;
......@@ -234,7 +235,7 @@ export class ReviewZoneWidget extends ZoneWidget {
display(lineNumber: number) {
const commentWidget = new CommentGlyphWidget(`review_${lineNumber}`, this.editor, lineNumber, () => {
// Does nothing when clicked
this.toggleExpand();
});
this.editor.layoutContentWidget(commentWidget);
......
......@@ -13,7 +13,7 @@ import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { IModelDecoration, IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/model';
import { IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import * as modes from 'vs/editor/common/modes';
import { peekViewEditorBackground } from 'vs/editor/contrib/referenceSearch/referencesWidget';
......@@ -251,14 +251,13 @@ export class ReviewController implements IEditorContribution {
if (this.canAddNewCommentToLine(lineNumber)) {
let newCommentInfo = this.getNewCommentAction(lineNumber);
if (!newCommentInfo) {
return;
}
// add new comment
this._reviewPanelVisible.set(true);
const [replyCommand, owner] = newCommentInfo;
this._zoneWidget = new ReviewZoneWidget(this.editor, owner, {
const { replyCommand, ownerId } = newCommentInfo;
this._zoneWidget = new ReviewZoneWidget(this.editor, ownerId, {
threadId: null,
resource: null,
comments: [],
......@@ -268,7 +267,7 @@ export class ReviewController implements IEditorContribution {
endLineNumber: lineNumber,
endColumn: 0
},
reply: newCommentInfo[0],
reply: replyCommand,
collapsibleState: CommentThreadCollapsibleState.Expanded,
}, replyCommand, {}, this.themeService, this.commandService);
......@@ -282,14 +281,13 @@ export class ReviewController implements IEditorContribution {
private addComment(lineNumber: number) {
let newCommentInfo = this.getNewCommentAction(lineNumber);
if (!newCommentInfo) {
return;
}
// add new comment
this._reviewPanelVisible.set(true);
const [replyCommand, owner] = newCommentInfo;
this._zoneWidget = new ReviewZoneWidget(this.editor, owner, {
const { replyCommand, ownerId } = newCommentInfo;
this._zoneWidget = new ReviewZoneWidget(this.editor, ownerId, {
threadId: null,
resource: null,
comments: [],
......@@ -299,7 +297,7 @@ export class ReviewController implements IEditorContribution {
endLineNumber: lineNumber,
endColumn: 0
},
reply: newCommentInfo[0],
reply: replyCommand,
collapsibleState: CommentThreadCollapsibleState.Expanded,
}, replyCommand, {}, this.themeService, this.commandService);
......@@ -333,40 +331,22 @@ export class ReviewController implements IEditorContribution {
}
}
getNewCommentAction(line: number): [modes.Command, number] {
const decorations = this.editor.getLineDecorations(line);
let activeDecoration: IModelDecoration;
if (decorations) {
for (const decoration of decorations) {
if (decoration.options.linesDecorationsClassName &&
decoration.options.linesDecorationsClassName.indexOf('commenting-range') > -1 &&
decoration.options.glyphMarginClassName.indexOf('review') < 0
) {
activeDecoration = decoration;
}
}
}
if (!activeDecoration) {
return null;
}
let cmd: modes.Command = null;
let owner: number = -1;
this.commentingRangeDecorationMap.forEach((value, key) => {
if (!cmd && value.indexOf(activeDecoration.id) > -1) {
// index
let infos = this._commentInfos.filter(info => info.owner === Number(key));
getNewCommentAction(line: number): { replyCommand: modes.Command, ownerId: number } {
for (let i = 0; i < this._commentInfos.length; i++) {
const commentInfo = this._commentInfos[i];
const lineWithinRange = commentInfo.commentingRanges.some(range =>
range.startLineNumber <= line && line <= range.endLineNumber
);
if (infos && infos.length) {
cmd = infos[0].reply;
owner = Number(key);
}
if (lineWithinRange) {
return {
replyCommand: commentInfo.reply,
ownerId: commentInfo.owner
};
}
});
}
return [cmd, owner];
return null;
}
canAddNewCommentToLine(line: number): boolean {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册