Skip to content

Commit b5c42d6

Browse files
committed
TinyMCE: views: correct cursor position after paste
Fixes #33174. git-svn-id: https://develop.svn.wordpress.org/trunk@33484 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8db3eee commit b5c42d6

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/wp-includes/js/mce-view.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -421,23 +421,29 @@
421421
*/
422422
replaceMarkers: function() {
423423
this.getMarkers( function( editor, node ) {
424+
var selected = node === editor.selection.getNode(),
425+
$viewNode;
426+
424427
if ( ! this.loader && $( node ).text() !== this.text ) {
425428
editor.dom.setAttrib( node, 'data-wpview-marker', null );
426429
return;
427430
}
428431

429-
editor.dom.replace(
430-
editor.dom.createFragment(
431-
'<div class="wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '">' +
432-
'<p class="wpview-selection-before">\u00a0</p>' +
433-
'<div class="wpview-body" contenteditable="false">' +
434-
'<div class="wpview-content wpview-type-' + this.type + '"></div>' +
435-
'</div>' +
436-
'<p class="wpview-selection-after">\u00a0</p>' +
437-
'</div>'
438-
),
439-
node
432+
$viewNode = editor.$(
433+
'<div class="wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '">' +
434+
'<p class="wpview-selection-before">\u00a0</p>' +
435+
'<div class="wpview-body" contenteditable="false">' +
436+
'<div class="wpview-content wpview-type-' + this.type + '"></div>' +
437+
'</div>' +
438+
'<p class="wpview-selection-after">\u00a0</p>' +
439+
'</div>'
440440
);
441+
442+
editor.$( node ).replaceWith( $viewNode );
443+
444+
if ( selected ) {
445+
editor.wp.setViewCursor( false, $viewNode[0] );
446+
}
441447
} );
442448
},
443449

src/wp-includes/js/tinymce/plugins/wpview/plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
729729
// Add to editor.wp
730730
editor.wp = editor.wp || {};
731731
editor.wp.getView = getView;
732+
editor.wp.setViewCursor = setViewCursor;
732733

733734
// Keep for back-compat.
734735
return {

0 commit comments

Comments
 (0)