Skip to content

Commit

Permalink
Fix #92794. allow customize placeholder for input box
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Apr 27, 2020
1 parent bfe0bb0 commit 0421b83
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/vs/editor/common/modes.ts
Expand Up @@ -1531,6 +1531,21 @@ export interface CommentReaction {
readonly canEdit?: boolean;
}

/**
* @internal
*/
export interface CommentOptions {
/**
* An optional string to show on the comment input box when it's collapsed.
*/
prompt?: string;

/**
* An optional string to show as placeholder in the comment input box when it's focused.
*/
placeHolder?: string;
}

/**
* @internal
*/
Expand Down
21 changes: 21 additions & 0 deletions src/vs/vscode.proposed.d.ts
Expand Up @@ -2054,4 +2054,25 @@ declare module 'vscode' {

//#endregion

//#region Comment
export interface CommentOptions {
/**
* An optional string to show on the comment input box when it's collapsed.
*/
prompt?: string;

/**
* An optional string to show as placeholder in the comment input box when it's focused.
*/
placeHolder?: string;
}

export interface CommentController {
/**
* Comment controller options
*/
options?: CommentOptions;
}

//#endregion
}
4 changes: 4 additions & 0 deletions src/vs/workbench/api/browser/mainThreadComments.ts
Expand Up @@ -177,6 +177,10 @@ export class MainThreadCommentController {
this._reactions = reactions;
}

get options() {
return this._features.options;
}

private readonly _threads: Map<number, MainThreadCommentThread> = new Map<number, MainThreadCommentThread>();
public activeCommentThread?: MainThreadCommentThread;

Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Expand Up @@ -135,6 +135,7 @@ export interface MainThreadCommandsShape extends IDisposable {
export interface CommentProviderFeatures {
reactionGroup?: modes.CommentReaction[];
reactionHandler?: boolean;
options?: modes.CommentOptions;
}

export type CommentThreadChanges = Partial<{
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/api/common/extHostComments.ts
Expand Up @@ -451,6 +451,18 @@ class ExtHostCommentController implements vscode.CommentController {
this._proxy.$updateCommentControllerFeatures(this.handle, { reactionHandler: !!handler });
}

private _options: modes.CommentOptions | undefined;

get options() {
return this._options;
}

set options(options: modes.CommentOptions | undefined) {
this._options = options;

this._proxy.$updateCommentControllerFeatures(this.handle, { options: this._options });
}

constructor(
private _extension: IExtensionDescription,
private _handle: number,
Expand Down
11 changes: 7 additions & 4 deletions src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts
Expand Up @@ -101,6 +101,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget

private _commentMenus: CommentMenus;

private _commentOptions: modes.CommentOptions | undefined;

constructor(
editor: ICodeEditor,
private _owner: string,
Expand Down Expand Up @@ -133,6 +135,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget

if (controller) {
commentControllerKey.set(controller.contextValue);
this._commentOptions = controller.options;
}

this._resizeObserver = null;
Expand Down Expand Up @@ -718,9 +721,9 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget

private createReplyButton() {
this._reviewThreadReplyButton = <HTMLButtonElement>dom.append(this._commentForm, dom.$('button.review-thread-reply-button'));
this._reviewThreadReplyButton.title = nls.localize('reply', "Reply...");
this._reviewThreadReplyButton.title = this._commentOptions?.prompt || nls.localize('reply', "Reply...");

this._reviewThreadReplyButton.textContent = nls.localize('reply', "Reply...");
this._reviewThreadReplyButton.textContent = this._commentOptions?.prompt || nls.localize('reply', "Reply...");
// bind click/escape actions for reviewThreadReplyButton and textArea
this._disposables.add(dom.addDisposableListener(this._reviewThreadReplyButton, 'click', _ => this.expandReplyArea()));
this._disposables.add(dom.addDisposableListener(this._reviewThreadReplyButton, 'focus', _ => this.expandReplyArea()));
Expand Down Expand Up @@ -768,8 +771,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
const placeholder = valueLength > 0
? ''
: hasExistingComments
? nls.localize('reply', "Reply...")
: nls.localize('newComment', "Type a new comment");
? (this._commentOptions?.prompt || nls.localize('reply', "Reply..."))
: (this._commentOptions?.placeHolder || nls.localize('newComment', "Type a new comment"));
const decorations = [{
range: {
startLineNumber: 0,
Expand Down

0 comments on commit 0421b83

Please sign in to comment.