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: comment min size #7915

Merged
merged 3 commits into from
Mar 11, 2024
Merged

Conversation

BeksOmega
Copy link
Collaborator

@BeksOmega BeksOmega commented Mar 8, 2024

The basics

The details

Resolves

Fixes N/A

Proposed Changes + Reasons

Makes it so we calculate the minimum size of the comment based on the size of the preview text. This way we'll never get preview text hanging off the edge of the comment.

Alternatively, I could have tried to truncate the preview text to fit within the available area, but this is super inefficient because it requires continual trial and error and layout recalculation. So instead of fitting the text to the area, I fit the area to the text.

Ideally the browser would just truncate the preview and add ellipses for us (then we could fit the text to the area), but SVG doesn't support that! So instead we have to do this complicated madness :P

Test Coverage

Tested that the minimum size is properly set with different text width, and with or without the delete icon.

Documentation

N/A

Additional Information

This doesn't work exactly like MakeCode's setup. For them, they always set the width to a specific width when collapsing (the length of 12 m characters, plus the ellipse) which causes a bug where it overlaps their icons. Instead when collapsing, we keep the width of the comment the same, just hide the text area.

They are able to implement their behavior using the onCollapse listener to set the width explicitly. So this isn't a blocker even though it's a difference in behavior.

But writing this did make me realize that I might need to change the calculation for positioning the preview text slightly to do what they want, so I'll look into that in a follow up. Tested and the current setup should be fine.

@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Mar 8, 2024
@BeksOmega BeksOmega marked this pull request as ready for review March 11, 2024 19:48
@BeksOmega BeksOmega requested a review from a team as a code owner March 11, 2024 19:48
Copy link
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

A few nits on comments, then LGTM.

@@ -43,4 +43,20 @@ export class Size {
}
return a.width === b.width && a.height === b.height;
}

/**
* Returns a new size with the maximum width and heigh values out of both
Copy link
Collaborator

Choose a reason for hiding this comment

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

heigh -> height

// Loop through listeners backwards in case they remove themselves.
for (let i = this.textChangeListeners.length - 1; i >= 0; i--) {
this.textChangeListeners[i](oldText, this.text);
}
}

private updateTextPreview(text: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add doc comment

return new Size(width, height);
}

private calcDeleteMargin(topBarSize: Size, deleteSize: Size) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add doc comment.

@BeksOmega BeksOmega enabled auto-merge (squash) March 11, 2024 20:56
@BeksOmega BeksOmega merged commit 30127db into google:rc/v11.0.0 Mar 11, 2024
6 checks passed
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.

2 participants