Ticket #36482: 36482.patch
File 36482.patch, 3.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/js/editor-expand.js
15 15 $visualEditor = $(), 16 16 $textTop = $( '#ed_toolbar' ), 17 17 $textEditor = $( '#content' ), 18 textEditor = $textEditor[0], 19 textEditorLength = 0, 18 20 $textEditorClone = $( '<div id="content-textarea-clone" class="wp-exclude-emoji"></div>' ), 21 textEditorClonelineHeight = parseInt( $textEditor.css( 'line-height' ), 10 ), 19 22 $bottom = $( '#post-status-info' ), 20 23 $menuBar = $(), 21 24 $statusBar = $(), … … 87 90 function textEditorKeyup( event ) { 88 91 var VK = jQuery.ui.keyCode, 89 92 key = event.keyCode, 90 range = document.createRange(),91 selStart = $textEditor[0].selectionStart,92 selEnd = $textEditor[0].selectionEnd,93 textNode = $textEditorClone[0].firstChild,94 93 buffer = 10, 95 offset, cursorTop, cursorBottom, editorTop, editorBottom;94 offset, cursorTop, editorTop; 96 95 97 if ( selStart && selEnd && selStart !== selEnd) {96 if ( key !== VK.UP && key !== VK.LEFT && key !== VK.BACKSPACE ) { 98 97 return; 99 98 } 100 99 101 // These are not TinyMCE ranges. 102 try { 103 range.setStart( textNode, selStart ); 104 range.setEnd( textNode, selEnd + 1 ); 105 } catch ( ex ) {} 106 107 offset = range.getBoundingClientRect(); 108 109 if ( ! offset.height ) { 110 return; 111 } 100 $textEditorClone.width( $textEditor.width() - 22 ); 101 $textEditorClone.text( $textEditor.val().substring( 0, $textEditor[0].selectionStart ) || ' ' ); 112 102 113 cursorTop = offset.top - buffer;114 cursor Bottom = cursorTop + offset.height +buffer;103 offset = $textEditorClone[0].getBoundingClientRect(); 104 cursorTop = offset.bottom + textEditorClonelineHeight - buffer; 115 105 editorTop = heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight; 116 editorBottom = heights.windowHeight - heights.bottomHeight;117 106 118 if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE )) {107 if ( cursorTop < editorTop ) { 119 108 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop ); 120 } else if ( cursorBottom > editorBottom ) {121 window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );122 109 } 123 110 } 124 111 125 112 function textEditorResize() { 113 var pageYOffset, height, 114 reduce = textEditorLength && textEditorLength > textEditor.value.length; 115 126 116 if ( ( mceEditor && ! mceEditor.isHidden() ) || ( ! mceEditor && initialMode === 'tinymce' ) ) { 127 117 return; 128 118 } 129 119 130 var textEditorHeight = $textEditor.height(),131 hiddenHeight;120 textEditorLength = textEditor.value.length; 121 height = textEditor.style.height; 132 122 133 $textEditorClone.width( $textEditor.width() - 22 );134 $textEditorClone.text( $textEditor.val() + ' ' );123 if ( reduce ) { 124 pageYOffset = window.pageYOffset; 135 125 136 hiddenHeight = $textEditorClone.height(); 126 textEditor.style.height = 'auto'; 127 textEditor.style.height = textEditor.scrollHeight + 'px'; 137 128 138 if ( hiddenHeight < autoresizeMinHeight ) { 139 hiddenHeight = autoresizeMinHeight; 129 window.scrollTo( window.pageXOffset, pageYOffset ); 130 } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { 131 textEditor.style.height = textEditor.scrollHeight + 'px'; 140 132 } 141 133 142 if ( h iddenHeight === textEditorHeight ) {143 return;134 if ( height !== textEditor.style.height ) { 135 adjust(); 144 136 } 145 146 $textEditor.height( hiddenHeight );147 148 adjust();149 137 } 150 138 151 139 // We need to wait for TinyMCE to initialize. … … 474 462 475 463 if ( event && event.deltaHeight > 0 && event.deltaHeight < 100 ) { 476 464 window.scrollBy( 0, event.deltaHeight ); 477 } else if ( advanced ) {465 } else if ( visual && advanced ) { 478 466 fixedBottom = true; 479 467 480 468 $statusBar.css( {