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

i/6444: Fix balloon toolbar items grouping on reappearance #7721

Closed
wants to merge 4 commits into from
Closed

Conversation

panr
Copy link
Contributor

@panr panr commented Jul 27, 2020

Suggested merge commit message (convention)

Fix (ui): Balloon toolbar will regroup items on reappearance after the editor resizing. Closes #6444.

@panr panr requested a review from oleq July 27, 2020 15:03
@panr panr changed the title i/6444: Fix toolbar balloon items grouping on reappearance i/6444: Fix balloon toolbar items grouping on reappearance Jul 27, 2020
@@ -772,6 +772,26 @@ describe( 'ToolbarView', () => {
sinon.assert.calledOnce( view._behavior._updateGrouping );
} );

it( 'does not update the state of grouped items if toolbar is not in the DOM', () => {
Copy link
Member

@oleq oleq Jul 28, 2020

Choose a reason for hiding this comment

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

This test is unrelated to the change (it is valid, though, it should stay). It passes with or without the fix. 

I think we're missing a twin to "should queue the update of the grouped items state when invisible (and execute it when visible again)" except that it should check element.remove() instead of element.style.display = 'none'.

@@ -630,6 +630,8 @@ class DynamicGrouping {
// nothing else. This happens, for instance, when the toolbar is detached from DOM and
// some logic adds or removes its #items.
if ( !this.viewElement.ownerDocument.body.contains( this.viewElement ) ) {
this.shouldUpdateGroupingOnNextResize = true;
Copy link
Member

Choose a reason for hiding this comment

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

This is a hack and it only hides the problem.

I did some logging in _enableGroupingOnResize() only to find out that the entry.contentRect.width has a wrong (outdated) value when the toolbar re-appears (4. from the original issue #6444). The value of entry.contentRect.width represents the width of the #viewElement when the toolbar was last resized, not when it re-appeared. This suggests the ResizeObserver implementation is buggy so maybe this is where the fix should land.

diff --git a/packages/ckeditor5-ui/src/toolbar/toolbarview.js b/packages/ckeditor5-ui/src/toolbar/toolbarview.js
index ea12e500ff..d5cc4d7160 100644
--- a/packages/ckeditor5-ui/src/toolbar/toolbarview.js
+++ b/packages/ckeditor5-ui/src/toolbar/toolbarview.js
@@ -728,6 +728,8 @@ class DynamicGrouping {

                   // TODO: Consider debounce.
                   this.resizeObserver = new ResizeObserver( this.viewElement, entry => {
+                           console.log( !previousWidth, previousWidth !== entry.contentRect.width, previousWidth, entry.contentRect.width );
+
                            if ( !previousWidth || previousWidth !== entry.contentRect.width || this.shouldUpdateGroupingOnNextResize ) {
                                     this.shouldUpdateGroupingOnNextResize = false;

Also, with your fix enabled the toolbar re-positions in a wrong place (Chrome). I wonder if this could be related to #7705. And maybe fb6b0dc was wrong because we're losing the non-zero->0 and 0->non-zero state changes. This all has to be checked.

Copy link
Contributor Author

@panr panr Jul 28, 2020

Choose a reason for hiding this comment

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

Oh damn it... I thought it would be easier to fix... Also, just tested it with fb6b0dc being reverted and... I can't reproduce the issue 🤔 Could you check it too and confirm? You always can find some edge cases ;-D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we should close this PR, because reverting fb6b0dc gives us the same results...

Copy link
Member

Choose a reason for hiding this comment

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

fb6b0dc was related to #6570. So before we revert anything we need to figure out what the impact of this change is gonna be.

Copy link
Contributor Author

@panr panr Aug 3, 2020

Choose a reason for hiding this comment

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

Regarding the #6570 issue, when I reverted the fb6b0dc on master block toolbar works fine. There's no sign of the bug I encountered before 🤔

@oleq Any chance you could confirm that when you have time?

btw. I know that sometimes you may have the positioning issue with the balloon toolbar, but it looks like it's quite rare, so maybe we should agree that having this issue is better than the balloon toolbar that won't expand? 🤔

@panr
Copy link
Contributor Author

panr commented Aug 7, 2020

I'm closing it due to #7795 fix.

@panr panr closed this Aug 7, 2020
@oleq oleq deleted the i/6444 branch August 10, 2020 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Safari] Balloon editor toolbar should always expand when there's enough space
2 participants