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

fix: Drag and Resize events for workspace comments #8217

Merged
merged 7 commits into from
Jun 26, 2024

Conversation

johnnesky
Copy link
Member

The basics

The details

Resolves

Fixes: #8113

Unblocks: google/blockly-samples#2330 and issues related to gonfunko/scratch-vm#3

Proposed Changes

Adds CommentDrag and CommentResize events.

The drag event is fired once (with isStart=false) when a comment movement drag is started, and again (with isStart=true) when the drag is finished. The existing CommentMove event will fire immediately afterward. This is consistent with block drag events which fire once at the start and once at the end.

The resize event is fired once when a comment resize drag is completed (with oldSize="$width, $height" and newSize="$width, $height"). This is the first type of event related to resizing as far as I know, although I tried to follow the example of CommentMove and BlockMove.

It occurs to me now while writing this that it may be desirable to also fire some kind of event when a resize drag begins. Maybe even the new CommentDrag event could be fired before CommentResize, similarly to how it is fired before CommentMove. The use-case I'm thinking of is google/blockly-samples#2330 where the content highlight fades away when a drag is begun and reappears when a drag is completed. As-is, we could still update the content highlight bounds when a resize drag is completed, but we wouldn't know when the resize drag is started. What do you think?

Reason for Changes

This is generally just a conspicuously missing set of events for workspace comments but we do have some use cases.

#8113 mentions using the new events for real time collaboration. Even in solo mode, this fixes the existing issue that you couldn't undo resizing a comment.

google/blockly-samples#2330 needs these events to hide the content highlight when a drag is started and recompute its bounds when the drag is completed.

gonfunko/scratch-vm#3 mentions needing these events for the Scratch unforking.

Test Coverage

I made unit tests for constructing and serializing the new events. I also manually tested that they are fired when expected. There's still some missing tests for resize events, for the same reason that #4577 is still open.

Documentation

I'm assuming https://developers.google.com/blockly/reference/js/blockly.events_namespace will be automatically updated?

Additional Information

I made a small change that might be considered breaking. In CommentView, size change listeners used to be called continuously while dragging the resize handle, but now are only called once when the drag is completed (so that the new resize event is only fired once). This is analogous to how CommentView handles text changes: it only notifies change listeners when the text input goes out of focus. The rendered comment display is still continuously updated while dragging, but the comment's internal size property is not updated until the end. As far as I know, CommentView and its change listeners are not publicly exported, but it's feasible that users may expect the comment's size property to be continuously updated. What do you think?

@johnnesky johnnesky requested a review from a team as a code owner June 15, 2024 05:33
@github-actions github-actions bot added the PR: fix Fixes a bug label Jun 15, 2024
@gonfunko gonfunko assigned gonfunko and unassigned rachel-fenichel Jun 18, 2024
@rachel-fenichel rachel-fenichel requested review from gonfunko and removed request for rachel-fenichel June 18, 2024 19:56
core/events/events_comment_resize.ts Outdated Show resolved Hide resolved
core/comments/workspace_comment.ts Outdated Show resolved Hide resolved
core/events/events_comment_drag.ts Outdated Show resolved Hide resolved
core/events/events_comment_resize.ts Outdated Show resolved Hide resolved
@gonfunko
Copy link
Contributor

LGTM but somebody officially on the core team will need to approve.

@BeksOmega BeksOmega self-requested a review June 24, 2024 16:22
@BeksOmega BeksOmega self-assigned this Jun 24, 2024
core/events/events_comment_resize.ts Outdated Show resolved Hide resolved
@johnnesky johnnesky merged commit 9a0619a into google:develop Jun 26, 2024
6 checks passed
@johnnesky johnnesky deleted the nesky_drag_comment branch July 12, 2024 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fire workspace comment resize events
4 participants