-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Don't show Link preview when no selection #58771
Conversation
Size Change: +22 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
// close the Link popover if there is no active selection | ||
// after the link was added - this can happen if the user | ||
// adds a link without any text selected | ||
if ( addingLink && ! value.activeFormats ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!value.activeFormats
would mean there are no active formats of any kind (including bold, italitc...etc). Is this intended? If not then the isActive
prop passed to this component might serve equally well:
const activeFormat = getActiveFormat( value, name ); | |
const isActive = activeFormat !== undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having no activeFormats entry - as opposed to an empty []
list - in value is specific to when the selection is collapsed after the format is applied to the inserted link.
This is why it feels this fix is exploiting some other problem :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice sleuthing.
I think this change could be complemented by #58179 which will only allow links to be created from a non-collapsed text selection.
WDYT?
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
When I insert the link my cursor doesn't get returned to the canvas: Feb-08-2024.14-41-14.mp4 |
6f03367
to
7411e44
Compare
Flaky tests detected in 7411e4463ef1d4f7da3e9b7df0f9f3f4e3fb885f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7835487221
|
7411e44
to
e51005f
Compare
…r the 1st render with no active edit
I like the idea here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now working as expected for me.
What?
Closes #58415
Why?
Bug fix
How?
Close the link ui preview if after the link is added there is no selection, hence no active format exists.
Alternatively another way would be to place the caret at the edge of the new link but inside the format. Although this seems like a better idea, I like the UX here better. I am also not sure there is a bug with caret placement, since there is no selection to count into.
My proposal is that if a link is added without any selection it should be an event that leaves the focus inline to allow for further text entry without the need to close distracting UI. So even if an alternate way is implemented I'd still favour the resulting UX of this PR.
Testing Instructions
Screenshots or screencast
close-link-preview-no-selection.mp4