TinyMCE: wptextpattern: reorder undo
After formatting on enter, undo should undo the formatting first, then undo the new line. See #31441. Built from https://develop.svn.wordpress.org/trunk@33507 git-svn-id: http://core.svn.wordpress.org/trunk@33474 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4837a3a43f
commit
e384cdab45
|
@ -25,7 +25,8 @@
|
||||||
{ start: '#####', format: 'h5' },
|
{ start: '#####', format: 'h5' },
|
||||||
{ start: '######', format: 'h6' },
|
{ start: '######', format: 'h6' },
|
||||||
{ start: '>', format: 'blockquote' }
|
{ start: '>', format: 'blockquote' }
|
||||||
];
|
],
|
||||||
|
refNode, refPattern;
|
||||||
|
|
||||||
editor.on( 'selectionchange', function() {
|
editor.on( 'selectionchange', function() {
|
||||||
canUndo = false;
|
canUndo = false;
|
||||||
|
@ -38,13 +39,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {
|
if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {
|
||||||
enter();
|
watchEnter();
|
||||||
}
|
}
|
||||||
}, true );
|
}, true );
|
||||||
|
|
||||||
editor.on( 'keyup', function( event ) {
|
editor.on( 'keyup', function( event ) {
|
||||||
if ( event.keyCode === VK.SPACEBAR && ! VK.modifierPressed( event ) ) {
|
if ( ! VK.modifierPressed( event ) ) {
|
||||||
|
if ( event.keyCode === VK.SPACEBAR ) {
|
||||||
space();
|
space();
|
||||||
|
} else if ( event.keyCode === VK.ENTER ) {
|
||||||
|
enter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -117,7 +122,7 @@
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
function enter() {
|
function watchEnter() {
|
||||||
var selection = editor.selection,
|
var selection = editor.selection,
|
||||||
rng = selection.getRng(),
|
rng = selection.getRng(),
|
||||||
offset = rng.startOffset,
|
offset = rng.startOffset,
|
||||||
|
@ -151,17 +156,22 @@
|
||||||
offset = Math.max( 0, offset - pattern.start.length );
|
offset = Math.max( 0, offset - pattern.start.length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refNode = node;
|
||||||
|
refPattern = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
function enter() {
|
||||||
|
if ( refNode ) {
|
||||||
editor.undoManager.add();
|
editor.undoManager.add();
|
||||||
|
|
||||||
editor.undoManager.transact( function() {
|
editor.undoManager.transact( function() {
|
||||||
node.deleteData( 0, pattern.start.length );
|
editor.formatter.apply( refPattern.format, {}, refNode );
|
||||||
|
refNode.deleteData( 0, refPattern.start.length );
|
||||||
editor.formatter.apply( pattern.format, {}, start );
|
|
||||||
|
|
||||||
rng.setStart( start, offset );
|
|
||||||
rng.collapse( true );
|
|
||||||
selection.setRng( rng );
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refNode = null;
|
||||||
|
refPattern = null;
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
} )( window.tinymce, window.setTimeout );
|
} )( window.tinymce, window.setTimeout );
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling),b}}function e(){var e,f,g=c.selection.getRng(),j=g.startContainer;j&&d(j)===j&&(e=j.parentNode,f=j.data,a.each(i,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){j.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){h=!0}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),h=g.startOffset,i=g.startContainer,k=d(i),l=j.length;if(k){for(b=k.data;l--;)if(0===b.indexOf(j[l].start)){e=j[l];break}if(e){if(k===i){if(a.trim(b)===e.start)return;h=Math.max(0,h-e.start.length)}c.undoManager.add(),c.undoManager.transact(function(){k.deleteData(0,e.start.length),c.formatter.apply(e.format,{},i),g.setStart(i,h),g.collapse(!0),f.setRng(g)})}}}var g=a.util.VK,h=!1,i=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],j=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){h=!1}),c.on("keydown",function(a){!h||a.keyCode!==g.BACKSPACE&&27!==a.keyCode||(c.undoManager.undo(),a.preventDefault()),a.keyCode!==g.ENTER||g.modifierPressed(a)||f()},!0),c.on("keyup",function(a){a.keyCode!==g.SPACEBAR||g.modifierPressed(a)||e()})})}(window.tinymce,window.setTimeout);
|
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling),b}}function e(){var e,f,g=c.selection.getRng(),h=g.startContainer;h&&d(h)===h&&(e=h.parentNode,f=h.data,a.each(l,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){h.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){k=!0}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),j=g.startOffset,k=g.startContainer,l=d(k),n=m.length;if(l){for(b=l.data;n--;)if(0===b.indexOf(m[n].start)){e=m[n];break}if(e){if(l===k){if(a.trim(b)===e.start)return;j=Math.max(0,j-e.start.length)}h=l,i=e}}}function g(){h&&(c.undoManager.add(),c.undoManager.transact(function(){c.formatter.apply(i.format,{},h),h.deleteData(0,i.start.length)})),h=null,i=null}var h,i,j=a.util.VK,k=!1,l=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],m=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){k=!1}),c.on("keydown",function(a){!k||a.keyCode!==j.BACKSPACE&&27!==a.keyCode||(c.undoManager.undo(),a.preventDefault()),a.keyCode!==j.ENTER||j.modifierPressed(a)||f()},!0),c.on("keyup",function(a){j.modifierPressed(a)||(a.keyCode===j.SPACEBAR?e():a.keyCode===j.ENTER&&g())})})}(window.tinymce,window.setTimeout);
|
Binary file not shown.
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.3-beta4-33506';
|
$wp_version = '4.3-beta4-33507';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue