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

Fix autogrow width issue #4393

Merged
merged 12 commits into from
Nov 24, 2020
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CKEditor 4 Changelog
Fixed Issues:

* [#4253](https://github.com/ckeditor/ckeditor4/issues/4253): Fixed: [Editor Placeholder](https://ckeditor.com/cke4/addon/editorplaceholder) plugin throws an error during editor initialization with [fullpage](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-fullPage) enabled when there is no `body` tag in editor content.
* [#4372](https://github.com/ckeditor/ckeditor4/issues/4372): Fixed: [Autogrow](https://ckeditor.com/cke4/addon/autogrow) plugin changes editor's width when used with absolute [`config.width`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-width) value.

## CKEditor 4.15.1

Expand Down
7 changes: 6 additions & 1 deletion plugins/autogrow/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@
// to the one set by previous resizeEditor() call.
if ( newHeight != currentHeight && lastHeight != newHeight ) {
newHeight = editor.fire( 'autoGrow', { currentHeight: currentHeight, newHeight: newHeight } ).newHeight;
editor.resize( editor.container.getStyle( 'width' ), newHeight, true );

var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ),
isBorderBox = boxSizingType === 'border-box',
width = editor.container.getSize( 'width', isBorderBox );

editor.resize( width, newHeight, true );
lastHeight = newHeight;
}

Expand Down
32 changes: 31 additions & 1 deletion tests/plugins/autogrow/_helpers/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,38 @@ var autogrowTools = ( function() {
return html;
}

function testEditorSizeWithContent( editorWidth ) {
bender.editorBot.create( {
name: 'editor_' + new Date().getTime(),
config: {
width: editorWidth
}
}, function( bot ) {
var paragraphsCount = 10;

bot.setData( autogrowTools.getTestContent( paragraphsCount ), function() {
var editor = bot.editor,
initialEditorSize = autogrowTools.getEditorSize( editor );

editor.once( 'afterCommandExec', function() {
resume( function name() {
var editorSize = autogrowTools.getEditorSize( editor );

assert.isTrue( editorSize.height > initialEditorSize.height, 'Editor height should increase' );
assert.areEqual( editorSize.width, initialEditorSize.width, 'Editor width should not change' );
} );
} );

editor.execCommand( 'autogrow' );

wait();
} );
} );
}

return {
getTestContent: getTestContent,
getEditorSize: getEditorSize
getEditorSize: getEditorSize,
testEditorSizeWithContent: testEditorSizeWithContent
};
} )();
31 changes: 28 additions & 3 deletions tests/plugins/autogrow/autogrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,37 @@
bender.editor = {};

bender.test( {
// (#4286)
'test autogrow': function() {
setUp: function() {
if ( bender.env.ie && bender.env.version < 9 ) {
assert.ignore();
}

},
// (#4372)
'test autogrow for editor width 200%': function() {
autogrowTools.testEditorSizeWithContent( '200%' );
},
// (#4372)
'test autogrow for editor width 20em': function() {
autogrowTools.testEditorSizeWithContent( '20em' );
},
// (#4372)
'test autogrow for editor width 200px': function() {
autogrowTools.testEditorSizeWithContent( '200px' );
},
// (#4372)
'test autogrow for editor width 200': function() {
autogrowTools.testEditorSizeWithContent( 200 );
},
// (#4372)
'test autogrow for editor width 0': function() {
autogrowTools.testEditorSizeWithContent( 0 );
},
// (#4372)
'test autogrow for editor width auto': function() {
autogrowTools.testEditorSizeWithContent( 'auto' );
},
// (#4286)
'test autogrow': function() {
var editor = this.editor,
bot = this.editorBot,
initialEditorSize = autogrowTools.getEditorSize( editor );
Expand Down
13 changes: 13 additions & 0 deletions tests/plugins/autogrow/manual/autogrowboxsize.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div contenteditable="true" id="editor">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
</div>

<script>
var editor = CKEDITOR.replace( 'editor', {
width: 300
} );
</script>
13 changes: 13 additions & 0 deletions tests/plugins/autogrow/manual/autogrowboxsize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@bender-tags: 4.15.2, bug, 4372
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, autogrow, basicstyles, toolbar, resize


1. Focus the editor.
2. Press `enter` multiple times to force the editor to resize.

## Expected
Editor width is not changing during auto-resize.

## Unexpected
With each vertical resize editor is shrinking for about 2 pixels.