-
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
Links: do not reposition container on selection change #14921
Conversation
The only remaining issue here is that the toolbar rerenders when you typing in the element. Fixing that now. |
b497ba1
to
ccaa94d
Compare
@@ -222,7 +236,12 @@ class InlineLinkUI extends Component { | |||
|
|||
return ( | |||
<PositionedAtSelection | |||
key={ `${ value.start }${ value.end }` /* Used to force rerender on selection change */ } |
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.
Possible dumb question: Couldn't a minimal solution just be to remove key
(and make no other changes)?
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.
What if you move the caret from one link to another?
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.
What if you move the caret from one link to another?
That's true. I wonder then if it could either act more like the Autocomplete
component in rendering Popover
with a getAnchorRect
that updates with the selection (but keeps the same element so not to unmount and re-trigger animation), or if PositionedAtSelection
should update its styling in response to selection changes rather than once at mount. Both of these would still update the position on each selection change, but at least would avoid the repeated animations.
I'm not totally sure the ramifications of either of these alternatives. Just trying to consider in terms of the least potential for impact.
15d85e8
to
18f4c57
Compare
end, | ||
}; | ||
delete newValue.activeFormats; | ||
const activeFormats = getActiveFormats( newValue ); |
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.
If we're working with a shallow clone, seems we might as well assign activeFormats
directly, rather than create another shallow clone below?
const newValue = {
...value,
activeFormats: getActiveFormats( newValue ),
start,
end,
};
@@ -763,6 +781,7 @@ export class RichText extends Component { | |||
// In all other cases, prevent default behaviour. | |||
event.preventDefault(); | |||
|
|||
const formats = createPrepareEditableTree( this.props )( 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.
I don't understand why this change is 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.
I'll comment, it's to make sure the boundaries work for annotations.
Updated the description:
|
e158037
to
f44a316
Compare
While I think we eventually want all the changes here to RichText, I'm going to make an alternative PR that doesn't touch as much existing code as it does now. |
Needs to be rebased after #14938 |
(I'm assuming this doesn't need to land for Gutenberg 5.5 and have removed it from the milestone accordingly) |
Closing for now. |
Description
Fixes #14872. It also makes sure that the container is positioned relative to the link element rather than the selection/caret, so it doesn't move when you move selection inside a link.
There are several steps that came to the fix.
PositionedAtSelection
so that it accepts aselector
prop, to select the closest matching element to calculate the position from rather than the caret.PositionedAtSelection
for every change in selection, we need to use the format object reference as an indicator to recreate, as each DOM element is a different object instance.getDerivedStateFromProps
to bump the key every time the active format object changes.activeFormats
inonSelectionChange
. The formats need to be taken from the current value to maintain references, not from the created value (from DOM) on the selection change.formatToValue
call for every input event, and no more need memoize it, and no more need forupdateFormats
, introduced in RichText: unify active formats, 'selectedFormat' and 'placeholderFormat' #14411.How has this been tested?
Screenshots
Types of changes
Checklist: