-
Notifications
You must be signed in to change notification settings - Fork 6
Revert view element's original width after resize #114
Conversation
@@ -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 ); |
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.
Isn't this.state.originalWidth
, well, the original width of the image? Or the naming here is ... unfortunate?
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.
Okay, it looks like it is the width at the start of the resize process 🤦♂ . Please confirm that this value is what we wanted.
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.
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
.
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.
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 ); |
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 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
?
|
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.
R-.
There is high chance that #115 will cause conflicts in the unit tests. Which are not a part of this PR yet, but for sure we'll be adding them. Asked for some clarifications in ckeditor/ckeditor5#6060 first. |
Closing this PR in favor of #122. This PR only handles commit (graceful image resize) and doesn't handle resize cancel, which could happen during the process. |
Fix: Revert view element's original width after resize and let the model handle it
Closes ckeditor/ckeditor5#6060