Skip to content

Commit

Permalink
feat: Allow specifying the default size of comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko committed Oct 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2dfd8c3 commit b5295a4
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/comments/comment_view.ts
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ export class CommentView implements IRenderedElement {
private textArea: HTMLTextAreaElement;

/** The current size of the comment in workspace units. */
private size: Size = new Size(120, 100);
private size: Size;

/** Whether the comment is collapsed or not. */
private collapsed: boolean = false;
@@ -102,6 +102,9 @@ export class CommentView implements IRenderedElement {
/** Size of this comment when the resize drag was initiated. */
private preResizeSize?: Size;

/** The default size of newly created comments. */
static defaultCommentSize = new Size(120, 100);

constructor(private readonly workspace: WorkspaceSvg) {
this.svgRoot = dom.createSvgElement(Svg.G, {
'class': 'blocklyComment blocklyEditable blocklyDraggable',
@@ -128,6 +131,7 @@ export class CommentView implements IRenderedElement {
workspace.getLayerManager()?.append(this, layers.BLOCK);

// Set size to the default size.
this.size = CommentView.defaultCommentSize;
this.setSizeWithoutFiringEvents(this.size);

// Set default transform (including inverted scale for RTL).
4 changes: 3 additions & 1 deletion core/comments/workspace_comment.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import * as idGenerator from '../utils/idgenerator.js';
import * as eventUtils from '../events/utils.js';
import {CommentMove} from '../events/events_comment_move.js';
import {CommentResize} from '../events/events_comment_resize.js';
import {CommentView} from './comment_view.js';

export class WorkspaceComment {
/** The unique identifier for this comment. */
@@ -20,7 +21,7 @@ export class WorkspaceComment {
private text = '';

/** The size of the comment in workspace units. */
private size = new Size(120, 100);
private size: Size;

/** Whether the comment is collapsed or not. */
private collapsed = false;
@@ -55,6 +56,7 @@ export class WorkspaceComment {
id?: string,
) {
this.id = id && !workspace.getCommentById(id) ? id : idGenerator.genUid();
this.size = CommentView.defaultCommentSize;

workspace.addTopComment(this);

0 comments on commit b5295a4

Please sign in to comment.