Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow specifying the default size of comments. #8618

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/comments/comment_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -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).
Expand Down
4 changes: 3 additions & 1 deletion core/comments/workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Loading