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

Revert view element's original width after resize #114

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/widgetresize/resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ export default class Resizer {
const unit = this._options.unit;
const newValue = ( unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth ) + this._options.unit;

this._options.editor.editing.view.change( writer => {
writer.setStyle( 'width', this.state.originalWidth + 'px', this._options.viewElement );
Copy link
Contributor

@scofalik scofalik Jan 13, 2020

Choose a reason for hiding this comment

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

Isn't this.state.originalWidth, well, the original width of the image? Or the naming here is ... unfortunate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, it looks like it is the width at the start of the resize process 🤦‍♂ . Please confirm that this value is what we wanted.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with originalWidth is that it is a calculated original width (as we need real pixels count for some math later on).

You could apply it back to the view before committing the results, but that would just cover up the problem - as it would still not necessarily be the original value (e.g. when initially image view has no width, or width in units like em, pt - which gets converted).

The proper solution would be to store view's initial width and reapply it just before calling onCommit.

Copy link
Contributor

Choose a reason for hiding this comment

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

A quick and dirty PoC pushed to i/6060a branch, see if that's what you're looking for.

} );

this._options.onCommit( newValue );

const domHandleHost = this._getHandleHost();
const domHandleHostRect = new Rect( domHandleHost );
this.redraw( domHandleHostRect );
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why this is needed and what happens there? AFAICS, the width is set there again. However, I assume that domHandleHostRect sizes are equal to the state.originalWidth and state.originalHeight?


this._cleanup();
}

Expand Down