diff --git src/wp-admin/edit-form-advanced.php src/wp-admin/edit-form-advanced.php
index 07c2dfe129..cddab85c1a 100644
|
|
|
if ( post_type_supports($post_type, 'editor') ) { |
| 639 | 639 | 'resize' => false, |
| 640 | 640 | 'wp_autoresize_on' => $_wp_editor_expand, |
| 641 | 641 | 'add_unload_trigger' => false, |
| 642 | | 'wp_keep_scroll_position' => true, |
| 643 | 642 | ), |
| 644 | 643 | ) ); ?> |
| 645 | 644 | <table id="post-status-info"><tbody><tr> |
diff --git src/wp-admin/js/editor.js src/wp-admin/js/editor.js
index ed77d3c755..ea4becc7dc 100644
|
|
|
window.wp = window.wp || {}; |
| 99 | 99 | |
| 100 | 100 | editorHeight = parseInt( textarea.style.height, 10 ) || 0; |
| 101 | 101 | |
| 102 | | var keepSelection = false; |
| 103 | | if ( editor ) { |
| 104 | | keepSelection = editor.getParam( 'wp_keep_scroll_position' ); |
| 105 | | } else { |
| 106 | | keepSelection = window.tinyMCEPreInit.mceInit[ id ] && |
| 107 | | window.tinyMCEPreInit.mceInit[ id ].wp_keep_scroll_position; |
| 108 | | } |
| 109 | | |
| 110 | | if ( keepSelection ) { |
| 111 | 102 | // Save the selection |
| 112 | | addHTMLBookmarkInTextAreaContent( $textarea ); |
| 113 | | } |
| | 103 | addHTMLBookmarkInTextAreaContent( $textarea, $ ); |
| 114 | 104 | |
| 115 | 105 | if ( editor ) { |
| 116 | 106 | editor.show(); |
| … |
… |
window.wp = window.wp || {}; |
| 126 | 116 | } |
| 127 | 117 | } |
| 128 | 118 | |
| 129 | | if ( editor.getParam( 'wp_keep_scroll_position' ) ) { |
| 130 | 119 | // Restore the selection |
| 131 | 120 | focusHTMLBookmarkInVisualEditor( editor ); |
| 132 | | } |
| 133 | 121 | } else { |
| 134 | 122 | tinymce.init( window.tinyMCEPreInit.mceInit[ id ] ); |
| 135 | 123 | } |
| … |
… |
window.wp = window.wp || {}; |
| 144 | 132 | return false; |
| 145 | 133 | } |
| 146 | 134 | |
| | 135 | var selectionRange = null; |
| 147 | 136 | if ( editor ) { |
| 148 | 137 | // Don't resize the textarea in iOS. The iframe is forced to 100% height there, we shouldn't match it. |
| 149 | 138 | if ( ! tinymce.Env.iOS ) { |
| … |
… |
window.wp = window.wp || {}; |
| 161 | 150 | } |
| 162 | 151 | } |
| 163 | 152 | |
| 164 | | var selectionRange = null; |
| 165 | | |
| 166 | | if ( editor.getParam( 'wp_keep_scroll_position' ) ) { |
| 167 | 153 | selectionRange = findBookmarkedPosition( editor ); |
| 168 | | } |
| 169 | 154 | |
| 170 | 155 | editor.hide(); |
| 171 | 156 | |
| … |
… |
window.wp = window.wp || {}; |
| 249 | 234 | function getShortcodeWrapperInfo( content, cursorPosition ) { |
| 250 | 235 | var contentShortcodes = getShortCodePositionsInText( content ); |
| 251 | 236 | |
| 252 | | for ( var i = 0; i < contentShortcodes.length; i++ ) { |
| 253 | | var element = contentShortcodes[ i ]; |
| 254 | | |
| 255 | | if ( cursorPosition >= element.startIndex && cursorPosition <= element.endIndex ) { |
| 256 | | return element; |
| 257 | | } |
| 258 | | } |
| | 237 | return _.find( contentShortcodes, function( element ) { |
| | 238 | return cursorPosition >= element.startIndex && cursorPosition <= element.endIndex; |
| | 239 | } ); |
| 259 | 240 | } |
| 260 | 241 | |
| 261 | 242 | /** |
| … |
… |
window.wp = window.wp || {}; |
| 264 | 245 | * @param {string} content The content we want to scan for shortcodes. |
| 265 | 246 | */ |
| 266 | 247 | function getShortcodesInText( content ) { |
| 267 | | var shortcodes = content.match( /\[+([\w_-])+/g ), |
| 268 | | result = []; |
| 269 | | |
| 270 | | if ( shortcodes ) { |
| 271 | | for ( var i = 0; i < shortcodes.length; i++ ) { |
| 272 | | var shortcode = shortcodes[ i ].replace( /^\[+/g, '' ); |
| 273 | | |
| 274 | | if ( result.indexOf( shortcode ) === -1 ) { |
| 275 | | result.push( shortcode ); |
| 276 | | } |
| 277 | | } |
| 278 | | } |
| | 248 | var shortcodes = content.match( /\[+([\w_-])+/g ); |
| | 249 | return _.uniq( |
| 279 | 250 | |
| 280 | | return result; |
| | 251 | _.map( shortcodes, function( element ) { |
| | 252 | return element.replace( /^\[+/g, '' ); |
| | 253 | } ) |
| | 254 | ); |
| 281 | 255 | } |
| 282 | 256 | |
| 283 | 257 | /** |
| … |
… |
window.wp = window.wp || {}; |
| 362 | 336 | shortcodesDetails.push( shortcodeInfo ); |
| 363 | 337 | } |
| 364 | 338 | |
| 365 | | /** |
| 366 | | * Get all URL matches, and treat them as embeds. |
| 367 | | * |
| 368 | | * Since there isn't a good way to detect if a URL by itself on a line is a previewable |
| 369 | | * object, it's best to treat all of them as such. |
| 370 | | * |
| 371 | | * This means that the selection will capture the whole URL, in a similar way shrotcodes |
| 372 | | * are treated. |
| 373 | | */ |
| 374 | | var urlRegexp = new RegExp( |
| 375 | | '(^|[\\n\\r][\\n\\r]|<p>)(https?:\\/\\/[^\s"]+?)(<\\/p>\s*|[\\n\\r][\\n\\r]|$)', 'gi' |
| 376 | | ); |
| 377 | | |
| 378 | | while ( shortcodeMatch = urlRegexp.exec( content ) ) { |
| 379 | | shortcodeInfo = { |
| 380 | | shortcodeName: 'url', |
| 381 | | showAsPlainText: false, |
| 382 | | startIndex: shortcodeMatch.index, |
| 383 | | endIndex: shortcodeMatch.index + shortcodeMatch[ 0 ].length, |
| 384 | | length: shortcodeMatch[ 0 ].length, |
| 385 | | isPreviewable: true, |
| 386 | | urlAtStartOfContent: shortcodeMatch[ 1 ] === '', |
| 387 | | urlAtEndOfContent: shortcodeMatch[ 3 ] === '' |
| 388 | | }; |
| 389 | | |
| 390 | | shortcodesDetails.push( shortcodeInfo ); |
| 391 | | } |
| 392 | | |
| 393 | 339 | return shortcodesDetails; |
| 394 | 340 | } |
| 395 | 341 | |
| … |
… |
window.wp = window.wp || {}; |
| 454 | 400 | */ |
| 455 | 401 | if ( voidElements.indexOf( isCursorStartInTag.tagType ) !== -1 ) { |
| 456 | 402 | cursorStart = isCursorStartInTag.ltPos; |
| 457 | | } else { |
| | 403 | } |
| | 404 | else { |
| 458 | 405 | cursorStart = isCursorStartInTag.gtPos; |
| 459 | 406 | } |
| 460 | 407 | } |
| … |
… |
window.wp = window.wp || {}; |
| 466 | 413 | |
| 467 | 414 | var isCursorStartInShortcode = getShortcodeWrapperInfo( content, cursorStart ); |
| 468 | 415 | if ( isCursorStartInShortcode && isCursorStartInShortcode.isPreviewable ) { |
| 469 | | /** |
| 470 | | * If a URL is at the start or the end of the content, |
| 471 | | * the selection doesn't work, because it inserts a marker in the text, |
| 472 | | * which breaks the embedURL detection. |
| 473 | | * |
| 474 | | * The best way to avoid that and not modify the user content is to |
| 475 | | * adjust the cursor to either after or before URL. |
| 476 | | */ |
| 477 | | if ( isCursorStartInShortcode.urlAtStartOfContent ) { |
| 478 | | cursorStart = isCursorStartInShortcode.endIndex; |
| 479 | | } else { |
| 480 | 416 | cursorStart = isCursorStartInShortcode.startIndex; |
| 481 | | } |
| 482 | 417 | } |
| 483 | 418 | |
| 484 | 419 | var isCursorEndInShortcode = getShortcodeWrapperInfo( content, cursorEnd ); |
| 485 | 420 | if ( isCursorEndInShortcode && isCursorEndInShortcode.isPreviewable ) { |
| 486 | | if ( isCursorEndInShortcode.urlAtEndOfContent ) { |
| 487 | | cursorEnd = isCursorEndInShortcode.startIndex; |
| 488 | | } else { |
| 489 | 421 | cursorEnd = isCursorEndInShortcode.endIndex; |
| 490 | | } |
| 491 | 422 | } |
| 492 | 423 | |
| 493 | 424 | return { |
| … |
… |
window.wp = window.wp || {}; |
| 525 | 456 | mode = htmlModeCursorStartPosition !== htmlModeCursorEndPosition ? 'range' : 'single', |
| 526 | 457 | |
| 527 | 458 | selectedText = null, |
| 528 | | cursorMarkerSkeleton = getCursorMarkerSpan( $$, '' ).attr( 'data-mce-type','bookmark' ); |
| | 459 | cursorMarkerSkeleton = getCursorMarkerSpan( $$, '' ); |
| 529 | 460 | |
| 530 | 461 | if ( mode === 'range' ) { |
| 531 | 462 | var markedText = textArea.value.slice( htmlModeCursorStartPosition, htmlModeCursorEndPosition ), |
| … |
… |
window.wp = window.wp || {}; |
| 540 | 471 | textArea.value = [ |
| 541 | 472 | textArea.value.slice( 0, htmlModeCursorStartPosition ), // text until the cursor/selection position |
| 542 | 473 | cursorMarkerSkeleton.clone() // cursor/selection start marker |
| 543 | | .addClass( 'mce_SELRES_start' )[0].outerHTML, |
| | 474 | .addClass( 'mce_SELRES_start')[0].outerHTML, |
| 544 | 475 | selectedText, // selected text with end cursor/position marker |
| 545 | 476 | textArea.value.slice( htmlModeCursorEndPosition ) // text from last cursor/selection position to end |
| 546 | 477 | ].join( '' ); |
| … |
… |
window.wp = window.wp || {}; |
| 557 | 488 | * @param {Object} editor TinyMCE editor instance. |
| 558 | 489 | */ |
| 559 | 490 | function focusHTMLBookmarkInVisualEditor( editor ) { |
| 560 | | var startNode = editor.$( '.mce_SELRES_start' ).attr( 'data-mce-bogus', 1 ), |
| 561 | | endNode = editor.$( '.mce_SELRES_end' ).attr( 'data-mce-bogus', 1 ); |
| | 491 | var startNode = editor.$( '.mce_SELRES_start' ), |
| | 492 | endNode = editor.$( '.mce_SELRES_end' ); |
| 562 | 493 | |
| 563 | 494 | if ( startNode.length ) { |
| 564 | 495 | editor.focus(); |
| … |
… |
window.wp = window.wp || {}; |
| 575 | 506 | } |
| 576 | 507 | } |
| 577 | 508 | |
| 578 | | if ( editor.getParam( 'wp_keep_scroll_position' ) ) { |
| 579 | 509 | scrollVisualModeToStartElement( editor, startNode ); |
| 580 | | } |
| | 510 | |
| 581 | 511 | |
| 582 | 512 | removeSelectionMarker( startNode ); |
| 583 | 513 | removeSelectionMarker( endNode ); |
| … |
… |
window.wp = window.wp || {}; |
| 619 | 549 | var elementTop = editor.$( element ).offset().top, |
| 620 | 550 | TinyMCEContentAreaTop = editor.$( editor.getContentAreaContainer() ).offset().top, |
| 621 | 551 | |
| 622 | | toolbarHeight = getToolbarHeight( editor ), |
| 623 | | |
| 624 | 552 | edTools = $( '#wp-content-editor-tools' ), |
| 625 | | edToolsHeight = 0, |
| 626 | | edToolsOffsetTop = 0; |
| | 553 | edToolsHeight = edTools.height(), |
| | 554 | edToolsOffsetTop = edTools.offset().top, |
| 627 | 555 | |
| 628 | | if ( edTools.length ) { |
| 629 | | edToolsHeight = edTools.height(); |
| 630 | | edToolsOffsetTop = edTools.offset().top; |
| 631 | | } |
| | 556 | toolbarHeight = getToolbarHeight( editor ), |
| 632 | 557 | |
| 633 | | var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, |
| | 558 | windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, |
| 634 | 559 | |
| 635 | 560 | selectionPosition = TinyMCEContentAreaTop + elementTop, |
| 636 | 561 | visibleAreaHeight = windowHeight - ( edToolsHeight + toolbarHeight ); |
| … |
… |
window.wp = window.wp || {}; |
| 751 | 676 | * This way we can adjust the selection to properly select only the content, ignoring |
| 752 | 677 | * whitespace inserted around the selected object by the Editor. |
| 753 | 678 | */ |
| 754 | | startElement.attr( 'data-mce-object-selection', 'true' ); |
| 755 | | endElement.attr( 'data-mce-object-selection', 'true' ); |
| | 679 | startElement.attr('data-mce-object-selection', 'true'); |
| | 680 | endElement.attr('data-mce-object-selection', 'true'); |
| 756 | 681 | |
| 757 | 682 | editor.$( startNode ).before( startElement[0] ); |
| 758 | 683 | editor.$( startNode ).after( endElement[0] ); |
diff --git src/wp-includes/class-wp-editor.php src/wp-includes/class-wp-editor.php
index 0743a840fe..954908be08 100644
|
|
|
final class _WP_Editors { |
| 983 | 983 | 'end_container_on_empty_block' => true, |
| 984 | 984 | 'wpeditimage_html5_captions' => true, |
| 985 | 985 | 'wp_lang_attr' => get_bloginfo( 'language' ), |
| 986 | | 'wp_keep_scroll_position' => false, |
| 987 | 986 | 'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ), |
| 988 | 987 | ); |
| 989 | 988 | |