-
Notifications
You must be signed in to change notification settings - Fork 4.7k
RichText: Remove focusPosition state #7651
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
Conversation
| this.setState( { formats, selectedNodeId: this.state.selectedNodeId + 1 } ); | ||
|
|
||
| if ( this.props.isViewportSmall ) { | ||
| let rect; |
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.
Why is this needing to be calculated at every node change event? Do we need to scroll every time on that event? Cc @mcsf.
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.
It almost certainly doesn't need to be. There's definitely room for improvement here, but I considered it outside the scope of the current task.
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.
Sounds good, I like the smaller PRs :)
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'm sure there's room for improvement. When we looked in #5769, there was no proper way to detect when the insertion of a character fills the whole width of a text container and forces the caret into a "new line" (a different height in the same container). 'nodechange' is definitely too generic, but per the comment, on nodechange we can work with the finalized TinyMCE instance and scroll to proper position.
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.
Perhaps the same kind of reasoning we're seeing in this PR (let's manage this ourselves with our vdom abstraction so as to batch positioning writes and reads) can be applied to the caret-tracking scrolling feature.
797afe9 to
c3fe6ce
Compare
mcsf
left a comment
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.
Looks great!
| const selection = window.getSelection(); | ||
|
|
||
| // Get position relative viewport. | ||
| const rect = getRectangleFromRange( selection.getRangeAt( 0 ) ); |
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.
Though improbable in the context in which we expect to use this component, should we guard against IndexSizeError by checking selection.rangeCount > 0 first?
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.
Though improbable in the context in which we expect to use this component, should we guard against
IndexSizeErrorby checkingselection.rangeCount > 0first?
Yep, seems very reasonable. Updated in the rebased 6eed870.
| this.setState( { formats, selectedNodeId: this.state.selectedNodeId + 1 } ); | ||
|
|
||
| if ( this.props.isViewportSmall ) { | ||
| let rect; |
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.
Perhaps the same kind of reasoning we're seeing in this PR (let's manage this ourselves with our vdom abstraction so as to batch positioning writes and reads) can be applied to the caret-tracking scrolling feature.
editor/components/rich-text/index.js
Outdated
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.
💯
c3fe6ce to
6eed870
Compare


Closes #6640
This pull request seeks to optimize the
RichTextcomponent to avoid needing to keep afocusPositionstate. This state was used exclusively for the positioning of the link popover overlay, and was calculated on everyNodeChangeevent in TinyMCE (which occurs fairly frequently). Its use ofElement#getBoundingClientRectwould also trigger browser relayout, thus being prone to layout thrashing (source). This revised implementation introduces a new component which is responsible for positioning itself relative the current selection at the time of its own mount. Therefore, it's only calculating its position when the link overlay is actually used.Testing instructions:
Verify there are no regressions in the display of the link format popover.
This was challenging to implement automated tests for, since JSDOM supports neither
window.getComputedStylenorHTMLElement#offsetParent. End-to-end tests may be wise for link additions, but the specific behavior here is relevant mostly to visual appearance, and we currently have no precedent for visual regression testing (though it may be worth exploring).