Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Fixed image resize flashing unexpected size #112

Merged
merged 16 commits into from Jan 3, 2020
Merged

Fixed image resize flashing unexpected size #112

merged 16 commits into from Jan 3, 2020

Conversation

mlewand
Copy link
Contributor

@mlewand mlewand commented Nov 15, 2019

Suggested merge commit message (convention)

Fix: Fixed image resize behavior upon short clicking a handle without dragging. Image will no longer became full width, nor will it briefly flash an unexpected size. Closes ckeditor/ckeditor5#5189 and closes ckeditor/ckeditor5#5195.

MINOR BREAKING CHANGE: Resizer options object now also takes an editor instance.


Additional information

  • note Since ResizerOptions now holds editor reference, it is no longer needed to keep downcastWriter so I'd also like to remove this property. I find it to be a minor breaking change, please confirm that.

Short overview of the problems:

  • flickering image at the first render (#5189)
    The issue is caused by the fact that we played a little against the UI with the initial implementation.

    The resizer was applying the new width styles directly to the img DOM element, skipping view abstraction. What happened there was that imageresize plugin added a img.image_resized class to the img's view, which gives it a 100% width. Since the view knew nothing about the width attribute, it did not add it while re-rendering img. Thus was getting full width for a brief moment, until the DOM img was modified once again directly.

    Now implementation works with view, that required me to pass editor instance to the resizer so I can request for a view writer.

  • committing full image width, when end user only clicks the handle (but does not move the cursor) (#5195)
    The problem is caused by the fact that commit() accesses an uninitialized state. And this occurs when user clicks the resize and releases the cursor but does not trigger mousemove event, thus the state is never initialized.

    It could be worked around in the imageresize plugin itself (just checking the state here), but the fix should be in the core and prevent commit from being issued.

Subprs:

@coveralls
Copy link

coveralls commented Nov 15, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 974c58d on i/5189 into b9cf062 on master.

@Reinmar Reinmar requested review from Mgsy and Reinmar November 15, 2019 13:42
Copy link
Member

@Mgsy Mgsy left a comment

Choose a reason for hiding this comment

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

LGTM.

* @private
* @type {module:engine/view/element~Element|null}
*/
this._resizerWrapperView = null;
Copy link
Member

Choose a reason for hiding this comment

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

The "view" doesn't mean that it's a view but it comes from the view so it's an adjective and should be the first word. Just like in the variable which you actually use below:

this._resizerWrapperView = viewResizerWrapper;

Next to the viewResizerWrapper you have a domResizerWrapper.

Copy link
Member

Choose a reason for hiding this comment

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

Please also fix the description of this property.

@Reinmar
Copy link
Member

Reinmar commented Nov 20, 2019

  • I find it to be a minor breaking change, please confirm that.

Yup, that's a minor.

mlewand and others added 2 commits November 20, 2019 10:43
…roperty.

Also linting: fixed line that violated 140 chars policy. This line skipped linter as it was commit straight from GH web interface.

MINOR BREAKING CHANGE: Removed downcastWriter property from the ResizerOptions interface.
@Reinmar Reinmar self-assigned this Nov 20, 2019
@Reinmar
Copy link
Member

Reinmar commented Nov 21, 2019

Unfortunately, I can see a significant performance drop after these changes.

This is master:

image

This is with the proposed changes:

image

The first task just got 3x longer. It's clearly visible that it contains a lot more calls.

Copy link
Member

@Reinmar Reinmar left a comment

Choose a reason for hiding this comment

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

IDK which bottleneck we're hitting right now, but I found a followup which may be worth checking if we identify the issue to be in mutation observer: ckeditor/ckeditor5#5600.

@mlewand
Copy link
Contributor Author

mlewand commented Dec 11, 2019

We just had a discussion with @Reinmar about this issue. Here are following actions:

More details:

The performance hit comes from the fact that now as the code use CKE5 views for DOM manipulation (does not do changes in the DOM directly), there are two View#change() requests. Each of these change requests finishes with a render event. And on render event the image inline toolbar is repositioned - this is where the performance penalty comes from.

On a side note there's also slightly related problem, where changes in our size UI are causing extra mutations. That's tracked in ckeditor/ckeditor5#5600.

@mlewand
Copy link
Contributor Author

mlewand commented Dec 17, 2019

This PR is blocked by ckeditor/ckeditor5#5964 as it needs to utilize WidgetToolbarRepository forceDisabled() method to hide the toolbar during the resize. Otherwise there are visible performance regression.

@Reinmar
Copy link
Member

Reinmar commented Dec 17, 2019

I tested the new disable/enable API as mentioned in #113. I think you can update this PR now.

@mlewand
Copy link
Contributor Author

mlewand commented Jan 2, 2020

Now resizer hides widget toolbar during the resize. I made a soft check on WidgetToolbarRepository plugin as it may or may not be available.

Also the actual toolbar hide logic was hooked to Resizer's begin, commit and cancel methods instead of mouse listener code directly, so that it works if resizer is operated using the API.

@mlewand mlewand requested a review from Mgsy January 2, 2020 15:30
Copy link
Member

@Reinmar Reinmar left a comment

Choose a reason for hiding this comment

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

If you click on the resize handle, the toolbar disappears and it never reappears, even if you select another widget.

mlewand added a commit to ckeditor/ckeditor5-image that referenced this pull request Jan 3, 2020
@FilipTokarski
Copy link
Member

FilipTokarski commented Jan 3, 2020

Toolbar works fine now.

There is a strange issue with resizing an image that is in Fancy editor (padding inside figure) and has width: not set. If you try to resize it veery slowly it suddenly jumps and shrinks just a bit. Sometimes jumps once again when releasing the mouse button. It happens only on the first attempt.
Browser: any / os: any

img_resize__err

@Mgsy
Copy link
Member

Mgsy commented Jan 3, 2020

☝️ same in Safari, however, I didn't notice weird behaviour after releasing the mouse button.

Besides this small issue, it looks good.

@Reinmar
Copy link
Member

Reinmar commented Jan 3, 2020

Yeah, the logic for handling an image without a width is tricky and can manifest like that. We had to take some shortcuts there – basically, we estimate the real width. 

Thanks for checking this PR. I'm merging it.

@Reinmar Reinmar merged commit d6a5c93 into master Jan 3, 2020
@Reinmar Reinmar deleted the i/5189 branch January 3, 2020 10:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants