Skip to content

Commit e7e1e97

Browse files
author
iseulde
committed
Editor: autoresize fixes for text
* Resize on backspace. * Don't make it smaller than the minimum height. Props azaozz, iseulde. See #36482. Built from https://develop.svn.wordpress.org/trunk@37603
1 parent 7935b52 commit e7e1e97

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

wp-admin/js/bookmarklet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-admin/js/editor-expand.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$textTop = $( '#ed_toolbar' ),
1717
$textEditor = $( '#content' ),
1818
textEditor = $textEditor[0],
19-
textEditorLength = 0,
19+
oldTextLength = 0,
2020
$bottom = $( '#post-status-info' ),
2121
$menuBar = $(),
2222
$statusBar = $(),
@@ -76,8 +76,6 @@
7676
}
7777

7878
function textEditorResize() {
79-
var reduce, scrollHeight;
80-
8179
if ( mceEditor && ! mceEditor.isHidden() ) {
8280
return;
8381
}
@@ -86,17 +84,28 @@
8684
return;
8785
}
8886

89-
reduce = textEditorLength > ( textEditorLength = textEditor.value.length );
90-
scrollHeight = textEditor.scrollHeight;
87+
var length = textEditor.value.length;
88+
var height = parseInt( textEditor.style.height, 10 );
9189

92-
if ( reduce ) {
90+
if ( length < oldTextLength ) {
91+
// textEditor.scrollHeight is not adjusted until the next line.
9392
textEditor.style.height = 'auto';
94-
textEditor.style.height = scrollHeight + 'px';
95-
adjust();
96-
} else if ( parseInt( textEditor.style.height, 10 ) < scrollHeight ) {
97-
textEditor.style.height = scrollHeight + 'px';
93+
94+
if ( textEditor.scrollHeight >= autoresizeMinHeight ) {
95+
textEditor.style.height = textEditor.scrollHeight + 'px';
96+
} else {
97+
textEditor.style.height = autoresizeMinHeight + 'px';
98+
}
99+
100+
if ( textEditor.scrollHeight < height ) {
101+
adjust();
102+
}
103+
} else if ( height < textEditor.scrollHeight ) {
104+
textEditor.style.height = textEditor.scrollHeight + 'px';
98105
adjust();
99106
}
107+
108+
oldTextLength = length;
100109
}
101110

102111
// We need to wait for TinyMCE to initialize.

0 commit comments

Comments
 (0)