提交 5a3c4d19 编写于 作者: P Peng Lyu

commentProvider can control collapse state of a thread

上级 e1c6d458
......@@ -214,6 +214,9 @@ export class ReviewMode implements vscode.DecorationProvider {
// No old threads match this thread, it is new
if (matchingCommentThread.length === 0) {
added.push(thread);
if (thread.resource.scheme === 'file') {
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Collapsed;
}
}
// Check if comment has been updated
......@@ -267,7 +270,7 @@ export class ReviewMode implements vscode.DecorationProvider {
return Promise.resolve(null);
}
private commentsToCommentThreads(comments: Comment[]): vscode.CommentThread[] {
private commentsToCommentThreads(comments: Comment[], collapsibleState: vscode.CommentThreadCollapsibleState = vscode.CommentThreadCollapsibleState.Expanded): vscode.CommentThread[] {
if (!comments || !comments.length) {
return [];
}
......@@ -297,6 +300,7 @@ export class ReviewMode implements vscode.DecorationProvider {
gravatar: comment.user.avatar_url
};
}),
collapsibleState: collapsibleState,
reply: this._reply
});
}
......@@ -361,7 +365,7 @@ export class ReviewMode implements vscode.DecorationProvider {
}
return {
threads: this.commentsToCommentThreads(matchingComments),
threads: this.commentsToCommentThreads(matchingComments, document.uri.scheme === 'file' ? vscode.CommentThreadCollapsibleState.Collapsed : vscode.CommentThreadCollapsibleState.Expanded),
commentingRanges: ranges,
reply: this._reply
};
......
......@@ -944,12 +944,24 @@ export interface CommentInfo {
reply?: Command;
}
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
export interface CommentThread {
readonly threadId: string;
readonly resource: string;
readonly range: IRange;
readonly comments: Comment[];
readonly reply: Command;
threadId: string;
resource: string;
range: IRange;
comments: Comment[];
collapsibleState?: CommentThreadCollapsibleState;
reply?: Command;
}
export interface NewCommentAction {
......
......@@ -793,6 +793,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
CompletionItemKind: CompletionItemKind,
SymbolKind: modes.SymbolKind,
IndentAction: IndentAction,
SuggestTriggerKind: modes.SuggestTriggerKind
SuggestTriggerKind: modes.SuggestTriggerKind,
CommentThreadCollapsibleState: modes.CommentThreadCollapsibleState
};
}
......@@ -5035,12 +5035,24 @@ declare namespace monaco.languages {
reply?: Command;
}
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1,
}
export interface CommentThread {
readonly threadId: string;
readonly resource: string;
readonly range: IRange;
readonly comments: Comment[];
readonly reply: Command;
threadId: string;
resource: string;
range: IRange;
comments: Comment[];
collapsibleState?: CommentThreadCollapsibleState;
reply?: Command;
}
export interface NewCommentAction {
......
......@@ -776,11 +776,23 @@ declare module 'vscode' {
reply?: Command;
}
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
interface CommentThread {
threadId: string;
resource: Uri;
range: Range;
comments: Comment[];
collapsibleState?: CommentThreadCollapsibleState;
reply?: Command;
}
......
......@@ -47,6 +47,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments
return;
}
if (!outerEditor.getModel()) {
return;
}
const outerEditorURI = outerEditor.getModel().uri;
this.provideComments(outerEditorURI).then(commentInfos => {
this._commentService.setComments(outerEditorURI, commentInfos);
......
......@@ -686,7 +686,9 @@ export function createApiFactory(
FileType: extHostTypes.FileType,
FoldingRangeList: extHostTypes.FoldingRangeList,
FoldingRange: extHostTypes.FoldingRange,
FoldingRangeType: extHostTypes.FoldingRangeType
FoldingRangeType: extHostTypes.FoldingRangeType,
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState
};
};
}
......
......@@ -103,6 +103,7 @@ function convertCommentThread(vscodeCommentThread: vscode.CommentThread, command
resource: vscodeCommentThread.resource.toString(),
range: extHostTypeConverter.fromRange(vscodeCommentThread.range),
comments: vscodeCommentThread.comments.map(convertComment),
collapsibleState: vscodeCommentThread.collapsibleState,
reply: vscodeCommentThread.reply ? commandsConverter.toInternal(vscodeCommentThread.reply) : null
};
}
......
......@@ -1868,3 +1868,15 @@ export enum FoldingRangeType {
}
//#endregion
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
\ No newline at end of file
......@@ -102,6 +102,9 @@ export class CommentNode {
}
}
const EXPAND_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-down';
const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-up';
export class ReviewZoneWidget extends ZoneWidget {
private _headElement: HTMLElement;
protected _primaryHeading: HTMLElement;
......@@ -113,7 +116,7 @@ export class ReviewZoneWidget extends ZoneWidget {
private _commentElements: CommentNode[];
private _resizeObserver: any;
private _onDidClose = new Emitter<ReviewZoneWidget>();
private _isCollapsed = true;
private _isCollapsed;
private _toggleAction: Action;
private _commentThread: modes.CommentThread;
public get commentThread(): modes.CommentThread {
......@@ -139,6 +142,7 @@ export class ReviewZoneWidget extends ZoneWidget {
this._owner = owner;
this._commentThread = commentThread;
this._replyCommand = replyCommand;
this._isCollapsed = commentThread.collapsibleState !== modes.CommentThreadCollapsibleState.Expanded;
this.create();
this.themeService.onThemeChange(this._applyTheme, this);
}
......@@ -183,15 +187,15 @@ export class ReviewZoneWidget extends ZoneWidget {
this._actionbarWidget = new ActionBar(actionsContainer.getHTMLElement(), {});
this._disposables.push(this._actionbarWidget);
this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), 'expand-review-action octicon octicon-chevron-down', true, () => {
this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => {
if (this._isCollapsed) {
this._bodyElement.style.display = 'block';
this._toggleAction.class = 'expand-review-action octicon octicon-chevron-up';
this._toggleAction.class = COLLAPSE_ACTION_CLASS;
this._isCollapsed = false;
}
else {
this._bodyElement.style.display = 'none';
this._toggleAction.class = 'expand-review-action octicon octicon-chevron-down';
this._toggleAction.class = EXPAND_ACTION_CLASS;
this._isCollapsed = true;
}
return null;
......@@ -270,7 +274,7 @@ export class ReviewZoneWidget extends ZoneWidget {
this._headElement.style.height = `${headHeight}px`;
this._headElement.style.lineHeight = this._headElement.style.height;
this._bodyElement.style.display = 'none';
this._bodyElement.style.display = this._isCollapsed ? 'none' : 'block';
this._commentsElement = $('div.comments-container').appendTo(this._bodyElement).getHTMLElement();
this._commentElements = [];
for (let i = 0; i < this._commentThread.comments.length; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册