Skip to content

Commit

Permalink
Add doc info to comments context keys (microsoft#174576)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored and c-claeys committed Feb 16, 2023
1 parent 1f7a5ae commit 2a51416
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus
import { Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable';
import { SmoothScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { DomEmitter } from 'vs/base/browser/event';
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';

export class CommentNode<T extends IRange | ICellRange> extends Disposable {
private _domNode: HTMLElement;
Expand Down Expand Up @@ -104,7 +105,10 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {

this._domNode = dom.$('div.review-comment');
this._contextKeyService = contextKeyService.createScoped(this._domNode);
this._commentContextValue = this._contextKeyService.createKey('comment', comment.contextValue);
this._commentContextValue = CommentContextKeys.commentContext.bindTo(this._contextKeyService);
if (this.comment.contextValue) {
this._commentContextValue.set(this.comment.contextValue);
}
this._commentMenus = this.commentService.getCommentMenus(this.owner);

this._domNode.tabIndex = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
this._styleElement = dom.createStyleSheet(this.container);


this._commentThreadContextValue = this._contextKeyService.createKey<string | undefined>('commentThread', undefined);
this._commentThreadContextValue = CommentContextKeys.commentThreadContext.bindTo(this._contextKeyService);
this._commentThreadContextValue.set(_commentThread.contextValue);

const commentControllerKey = this._contextKeyService.createKey<string | undefined>('commentController', undefined);
const commentControllerKey = CommentContextKeys.commentControllerContext.bindTo(this._contextKeyService);
const controller = this.commentService.getCommentController(this._owner);

if (controller) {
if (controller?.contextValue) {
commentControllerKey.set(controller.contextValue);
}

Expand Down
20 changes: 17 additions & 3 deletions src/vs/workbench/contrib/comments/common/commentContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';


export namespace CommentContextKeys {
/**
* A context key that is set when the comment thread has no comments.
*/
export const commentThreadIsEmpty = new RawContextKey<boolean>('commentThreadIsEmpty', false);
export const commentThreadIsEmpty = new RawContextKey<boolean>('commentThreadIsEmpty', false, { type: 'boolean', description: nls.localize('commentThreadIsEmpty', "Set when the comment thread has no comments") });
/**
* A context key that is set when the comment has no input.
*/
export const commentIsEmpty = new RawContextKey<boolean>('commentIsEmpty', false);
}
export const commentIsEmpty = new RawContextKey<boolean>('commentIsEmpty', false, { type: 'boolean', description: nls.localize('commentIsEmpty', "Set when the comment has no input") });
/**
* The context value of the comment.
*/
export const commentContext = new RawContextKey<string>('comment', undefined, { type: 'string', description: nls.localize('comment', "The context value of the comment") });
/**
* The context value of the comment thread.
*/
export const commentThreadContext = new RawContextKey<string>('commentThread', undefined, { type: 'string', description: nls.localize('commentThread', "The context value of the comment thread") });
/**
* The comment controller id associated with a comment thread.
*/
export const commentControllerContext = new RawContextKey<string>('commentController', undefined, { type: 'string', description: nls.localize('commentController', "The comment controller id associated with a comment thread") });
}

0 comments on commit 2a51416

Please sign in to comment.