-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Keep a copy of anchor ref to preserve highlighted text selection #36263
Keep a copy of anchor ref to preserve highlighted text selection #36263
Conversation
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 tests well!
@jorgefilipecosta @ellatrix I’ve tested that this fixes issue #36254 in |
This has been cherry-picked into https://github.com/WordPress/gutenberg/tree/release/11.8. |
* @param {any} value | ||
* @return {any} value | ||
*/ | ||
export function useCachedTruthy( value ) { |
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 hook seem a bit misplaced. If we need to be a public API, it should be on the "compose" package (more generic as it has nothing to do with block-editor). But personally, I see it only used once and I'm not sure this hook is very valuable outside that use-case so why not just move it close to its current usage?
Also was this cherry-picked to 10.9 as well, since 10.9 is now branched, any cherry-pick made to 10.8 should also be made to 10.9 or the commit won't be on the next major release. |
@youknowriad jinx! I just did that, and also released RC2 with it https://github.com/WordPress/gutenberg/releases/tag/v11.9.0-rc.2. Thanks for the reminder, anyway! 🙇🏻 |
Description
When highlighting a text to change its color, we use
document.currentView.getSelection
to determine what's selected on the screen. But when you try to type in the color you want using the custom color input, you're also discarding the selection you'd made of the text you want to colorize.So when
useAnchorRef
goes to look for the<mark>
element within the selected text, it won't find it, since it's actually looking inside the input field.This PR proposes caching the truthy value of the selection anchor, so user can select other text (like the color string inside the input) without losing track of the text they want to format.
How has this been tested?
Luckily, the issue is reproducible on trunk here. This change demonstrably fixes it.
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).Fixes #36254 and Automattic/wp-calypso#57687