From 713f23ce97189dd5f1869b01559ee4e03d1b7e4e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 1 Oct 2024 10:57:35 -0700 Subject: [PATCH] feat: Allow specifying the placeholder text of workspace comments. --- core/comments/comment_view.ts | 5 +++++ core/comments/rendered_workspace_comment.ts | 5 +++++ core/contextmenu_items.ts | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/comments/comment_view.ts b/core/comments/comment_view.ts index bda2b9762a8..798f51f961a 100644 --- a/core/comments/comment_view.ts +++ b/core/comments/comment_view.ts @@ -684,6 +684,11 @@ export class CommentView implements IRenderedElement { this.onTextChange(); } + /** Sets the placeholder text displayed for an empty comment. */ + setPlaceholderText(text: string) { + this.textArea.placeholder = text; + } + /** Registers a callback that listens for text changes. */ addTextChangeListener(listener: (oldText: string, newText: string) => void) { this.textChangeListeners.push(listener); diff --git a/core/comments/rendered_workspace_comment.ts b/core/comments/rendered_workspace_comment.ts index 79caf6a1d58..3144702ae09 100644 --- a/core/comments/rendered_workspace_comment.ts +++ b/core/comments/rendered_workspace_comment.ts @@ -104,6 +104,11 @@ export class RenderedWorkspaceComment this.view.setText(text); } + /** Sets the placeholder text displayed if the comment is empty. */ + setPlaceholderText(text: string): void { + this.view.setPlaceholderText(text); + } + /** Sets the size of the comment. */ override setSize(size: Size) { // setSize will trigger the change listener that updates diff --git a/core/contextmenu_items.ts b/core/contextmenu_items.ts index 254906ce7ff..f1d3293a4db 100644 --- a/core/contextmenu_items.ts +++ b/core/contextmenu_items.ts @@ -617,7 +617,7 @@ export function registerCommentCreate() { if (!workspace) return; eventUtils.setGroup(true); const comment = new RenderedWorkspaceComment(workspace); - comment.setText(Msg['WORKSPACE_COMMENT_DEFAULT_TEXT']); + comment.setPlaceholderText(Msg['WORKSPACE_COMMENT_DEFAULT_TEXT']); comment.moveTo( pixelsToWorkspaceCoords( new Coordinate(e.clientX, e.clientY),