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: visual comment selection #7996

Merged
merged 2 commits into from
Apr 5, 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
29 changes: 29 additions & 0 deletions core/comments/comment_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class CommentView implements IRenderedElement {
/** The root group element of the comment view. */
private svgRoot: SVGGElement;

/**
* The svg rect element that we use to create a hightlight around the comment.
*/
private highlightRect: SVGRectElement;

/** The group containing all of the top bar elements. */
private topBarGroup: SVGGElement;

Expand Down Expand Up @@ -99,6 +104,8 @@ export class CommentView implements IRenderedElement {
'class': 'blocklyComment blocklyEditable',
});

this.highlightRect = this.createHighlightRect(this.svgRoot);

({
topBarGroup: this.topBarGroup,
topBarBackground: this.topBarBackground,
Expand All @@ -124,6 +131,17 @@ export class CommentView implements IRenderedElement {
this.moveTo(new Coordinate(0, 0));
}

/**
* Creates the rect we use for highlighting the comment when it's selected.
*/
private createHighlightRect(svgRoot: SVGGElement): SVGRectElement {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tsdoc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to turn the lint warnings for this back on?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

return dom.createSvgElement(
Svg.RECT,
{'class': 'blocklyCommentHighlight'},
svgRoot,
);
}

/**
* Creates the top bar and the elements visually within it.
* Registers event listeners.
Expand Down Expand Up @@ -293,6 +311,8 @@ export class CommentView implements IRenderedElement {

this.svgRoot.setAttribute('height', `${size.height}`);
this.svgRoot.setAttribute('width', `${size.width}`);
this.highlightRect.setAttribute('height', `${size.height}`);
this.highlightRect.setAttribute('width', `${size.width}`);

this.updateTopBarSize(size);
this.updateTextAreaSize(size, topBarSize);
Expand Down Expand Up @@ -816,4 +836,13 @@ css.register(`
transform: scale(-1, 1);
cursor: sw-resize;
}
.blocklyCommentHighlight {
fill: none;
}
.blocklySelected .blocklyCommentHighlight {
stroke: #fc3;
stroke-width: 3px;
}
`);
10 changes: 8 additions & 2 deletions core/comments/rendered_workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ export class RenderedWorkspaceComment
this.dragStrategy.revertDrag();
}

select(): void {}
/** Visually highlights the comment. */
select(): void {
dom.addClass(this.getSvgRoot(), 'blocklySelected');
}

unselect(): void {}
/** Visually unhighlights the comment. */
unselect(): void {
dom.removeClass(this.getSvgRoot(), 'blocklySelected');
}
}
6 changes: 6 additions & 0 deletions core/gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ export class Gesture {
this.workspaceDragger.endDrag(this.currentDragDeltaXY);
} else if (this.isBubbleClick()) {
// Do nothing, bubbles don't currently respond to clicks.
} else if (this.isCommentClick()) {
// Do nothing, comments don't currently respond to clicks.
} else if (this.isFieldClick()) {
this.doFieldClick();
} else if (this.isIconClick()) {
Expand Down Expand Up @@ -1075,6 +1077,10 @@ export class Gesture {
return hasStartBubble && !this.hasExceededDragRadius;
}

private isCommentClick(): boolean {
return !!this.startComment && !this.hasExceededDragRadius;
}

/**
* Whether this gesture is a click on a block. This should only be called
* when ending a gesture (pointerup).
Expand Down