diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.js b/wp-includes/js/tinymce/plugins/wpview/plugin.js
index d39faf5a69..360e418bc9 100644
--- a/wp-includes/js/tinymce/plugins/wpview/plugin.js
+++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js
@@ -8,7 +8,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
VK = tinymce.util.VK,
TreeWalker = tinymce.dom.TreeWalker,
toRemove = false,
- cursorInterval, lastKeyDownNode, setViewCursorTries;
+ firstFocus = true,
+ cursorInterval, lastKeyDownNode, setViewCursorTries, focus;
function getView( node ) {
return editor.dom.getParent( node, function( node ) {
@@ -349,10 +350,30 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
selection = editor.selection,
node = selection.getNode(),
view = getView( node ),
- cursorBefore, cursorAfter;
+ cursorBefore, cursorAfter,
+ range, clonedRange, tempRange;
lastKeyDownNode = node;
+ // Make sure we don't delete part of a view.
+ // If the range ends or starts with the view, we'll need to trim it.
+ if ( ! selection.isCollapsed() ) {
+ range = selection.getRng();
+
+ if ( view = getView( range.endContainer ) ) {
+ clonedRange = range.cloneRange();
+ selection.select( view.previousSibling, true );
+ selection.collapse();
+ tempRange = selection.getRng();
+ clonedRange.setEnd( tempRange.endContainer, tempRange.endOffset );
+ selection.setRng( clonedRange );
+ } else if ( view = getView( range.startContainer ) ) {
+ clonedRange = range.cloneRange();
+ clonedRange.setStart( view.nextSibling, 0 );
+ selection.setRng( clonedRange );
+ }
+ }
+
if ( ! view ) {
return;
}
@@ -375,30 +396,26 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
}
}
} else {
- handleEnter( view, true );
+ setViewCursor( true, view );
}
event.preventDefault();
} else if ( cursorAfter && ( keyCode === VK.DOWN || keyCode === VK.RIGHT ) ) {
if ( view.nextSibling ) {
if ( getView( view.nextSibling ) ) {
- setViewCursor( false, view.nextSibling );
+ setViewCursor( keyCode === VK.RIGHT, view.nextSibling );
} else {
selection.setCursorLocation( view.nextSibling, 0 );
}
- } else {
- handleEnter( view );
}
event.preventDefault();
} else if ( cursorBefore && ( keyCode === VK.UP || keyCode === VK.LEFT ) ) {
if ( view.previousSibling ) {
if ( getView( view.previousSibling ) ) {
- setViewCursor( true, view.previousSibling );
+ setViewCursor( keyCode === VK.UP, view.previousSibling );
} else {
selection.select( view.previousSibling, true );
selection.collapse();
}
- } else {
- handleEnter( view, true );
}
event.preventDefault();
} else if ( cursorBefore && keyCode === VK.DOWN ) {
@@ -409,7 +426,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
selection.setCursorLocation( view.nextSibling, 0 );
}
} else {
- handleEnter( view );
+ setViewCursor( false, view );
}
event.preventDefault();
} else if ( ( cursorAfter && keyCode === VK.LEFT ) || ( cursorBefore && keyCode === VK.RIGHT ) ) {
@@ -465,12 +482,35 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
return;
}
- if ( keyCode === VK.LEFT || keyCode === VK.UP ) {
+ if ( keyCode === VK.LEFT ) {
setViewCursor( true, view );
deselect();
- } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) {
+ } else if ( keyCode === VK.UP ) {
+ if ( view.previousSibling ) {
+ if ( getView( view.previousSibling ) ) {
+ setViewCursor( true, view.previousSibling );
+ } else {
+ selection.select( view.previousSibling, true );
+ selection.collapse();
+ }
+ } else {
+ setViewCursor( true, view );
+ }
+ deselect();
+ } else if ( keyCode === VK.RIGHT ) {
setViewCursor( false, view );
deselect();
+ } else if ( keyCode === VK.DOWN ) {
+ if ( view.nextSibling ) {
+ if ( getView( view.nextSibling ) ) {
+ setViewCursor( false, view.nextSibling );
+ } else {
+ selection.setCursorLocation( view.nextSibling, 0 );
+ }
+ } else {
+ setViewCursor( false, view );
+ }
+ deselect();
} else if ( keyCode === VK.ENTER ) {
handleEnter( view );
} else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
@@ -511,6 +551,26 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
}
});
+ editor.on( 'focus', function() {
+ var view;
+
+ focus = true;
+ editor.dom.addClass( editor.getBody(), 'has-focus' );
+
+ // Edge case: show the fake caret when the editor is focused for the first time
+ // and the first element is a view.
+ if ( firstFocus && ( view = getView( editor.getBody().firstChild ) ) ) {
+ setViewCursor( true, view );
+ }
+
+ firstFocus = false;
+ } );
+
+ editor.on( 'blur', function() {
+ focus = false;
+ editor.dom.removeClass( editor.getBody(), 'has-focus' );
+ } );
+
editor.on( 'nodechange', function( event ) {
var dom = editor.dom,
views = editor.dom.select( '.wpview-wrap' ),
@@ -526,7 +586,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
dom.removeClass( views, 'wpview-selection-after' );
dom.removeClass( views, 'wpview-cursor-hide' );
- if ( view ) {
+ if ( view && editor.selection.isCollapsed() && focus ) {
if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) {
setViewCursorTries = 0;
diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js
index 4a1ba5ca57..191ca23acb 100644
--- a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js
+++ b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js
@@ -1 +1 @@
-tinymce.PluginManager.add("wpview",function(a){function b(b){return a.dom.getParent(b,function(b){return a.dom.hasClass(b,"wpview-wrap")})}function c(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function d(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function e(a){a.stopPropagation()}function f(b,c){var d=b?"before":"after",e=b?0:1;a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function g(b,c){var d,e=a.dom;!c&&b.nextSibling&&e.isEmpty(b.nextSibling)&&"P"===b.nextSibling.nodeName?d=b.nextSibling:c&&b.previousSibling&&e.isEmpty(b.previousSibling)&&"P"===b.previousSibling.nodeName?d=b.previousSibling:(d=e.create("p"),o.ie&&o.ie<11||(d.innerHTML='
'),c?b.parentNode.insertBefore(d,b):e.insertAfter(d,b)),i(),a.getBody().focus(),a.selection.setCursorLocation(d,0),a.nodeChanged()}function h(b){var d,f=a.dom;b!==k&&(i(),k=b,f.setAttrib(b,"data-mce-selected",1),d=f.create("div",{"class":"wpview-clipboard",contenteditable:"true"},c(b)),a.dom.select(".wpview-body",b)[0].appendChild(d),f.bind(d,"beforedeactivate focusin focusout",e),f.bind(k,"beforedeactivate focusin focusout",e),a.getBody().focus(),a.selection.select(d,!0),a.nodeChanged())}function i(){var b,c=a.dom;k&&(b=a.dom.select(".wpview-clipboard",k)[0],c.unbind(b),c.remove(b),c.unbind(k,"beforedeactivate focusin focusout click mouseup",e),c.setAttrib(k,"data-mce-selected",null)),k=null}function j(a){return a.replace(/
"+window.decodeURIComponent(b)+"
":""}))}),a.on("keydown",function(c){if(!(c.metaKey||c.ctrlKey||i>=112&&123>=i||k)){var d,e,i=c.keyCode,j=a.dom,l=a.selection,n=l.getNode(),o=b(n);m=n,o&&((d=j.hasClass(o,"wpview-selection-before"))||(e=j.hasClass(o,"wpview-selection-after")))&&(e&&i===p.UP||d&&i===p.BACKSPACE?(o.previousSibling?b(o.previousSibling)?f(!1,o.previousSibling):j.isEmpty(o.previousSibling)&&i===p.BACKSPACE?j.remove(o.previousSibling):(l.select(o.previousSibling,!0),l.collapse()):g(o,!0),c.preventDefault()):!e||i!==p.DOWN&&i!==p.RIGHT?!d||i!==p.UP&&i!==p.LEFT?d&&i===p.DOWN?(o.nextSibling?b(o.nextSibling)?f(!0,o.nextSibling):l.setCursorLocation(o.nextSibling,0):g(o),c.preventDefault()):e&&i===p.LEFT||d&&i===p.RIGHT?(h(o),c.preventDefault(),c.stopImmediatePropagation()):e&&i===p.BACKSPACE?(j.remove(o),c.preventDefault()):e?g(o):d&&g(o,!0):(o.previousSibling?b(o.previousSibling)?f(!0,o.previousSibling):(l.select(o.previousSibling,!0),l.collapse()):g(o,!0),c.preventDefault()):(o.nextSibling?b(o.nextSibling)?f(!1,o.nextSibling):l.setCursorLocation(o.nextSibling,0):g(o),c.preventDefault()),i===p.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,h=c.keyCode,j=a.selection;if(k){if(c.metaKey||c.ctrlKey||h>=112&&123>=h)return void(!c.metaKey&&!c.ctrlKey||88!==h&&h!==p.BACKSPACE||(88===h?r=k:a.dom.remove(k)));if(d=b(j.getNode()),d!==k)return void i();h===p.LEFT||h===p.UP?(f(!0,d),i()):h===p.RIGHT||h===p.DOWN?(f(!1,d),i()):h===p.ENTER?g(d):(h===p.DELETE||h===p.BACKSPACE)&&e.remove(k),c.preventDefault()}}),a.on("keydown",function(c){var d,e,g,h=a.selection;c.keyCode===p.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(g=b(d.previousSibling))&&(f(!1,g),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(g=b(d.previousSibling))&&(f(!1,g),c.preventDefault()))}),a.on("keyup",function(){r&&(a.dom.remove(r),r=!1)}),a.on("nodechange",function(c){var d=a.dom,e=a.dom.select(".wpview-wrap"),g=c.element.className,h=b(c.element),i=m;if(m=!1,clearInterval(l),d.removeClass(e,"wpview-selection-before"),d.removeClass(e,"wpview-selection-after"),d.removeClass(e,"wpview-cursor-hide"),h)if("wpview-selection-before"===g||"wpview-selection-after"===g){if(n=0,i===h.previousSibling)return void f(!0,h);if(i===h.nextSibling)return void f(!1,h);d.addClass(h,g),l=setInterval(function(){d.hasClass(h,"wpview-cursor-hide")?d.removeClass(h,"wpview-cursor-hide"):d.addClass(h,"wpview-cursor-hide")},500)}else k||n||(n++,f(!0,h))}),{getViewText:c,setViewText:d}}); \ No newline at end of file +tinymce.PluginManager.add("wpview",function(a){function b(b){return a.dom.getParent(b,function(b){return a.dom.hasClass(b,"wpview-wrap")})}function c(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function d(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function e(a){a.stopPropagation()}function f(b,c){var d=b?"before":"after",e=b?0:1;a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function g(b,c){var d,e=a.dom;!c&&b.nextSibling&&e.isEmpty(b.nextSibling)&&"P"===b.nextSibling.nodeName?d=b.nextSibling:c&&b.previousSibling&&e.isEmpty(b.previousSibling)&&"P"===b.previousSibling.nodeName?d=b.previousSibling:(d=e.create("p"),p.ie&&p.ie<11||(d.innerHTML='"+window.decodeURIComponent(b)+"
":""}))}),a.on("keydown",function(c){if(!(c.metaKey||c.ctrlKey||n>=112&&123>=n||k)){var d,e,i,j,l,n=c.keyCode,o=a.dom,p=a.selection,r=p.getNode(),s=b(r);m=r,p.isCollapsed()||(i=p.getRng(),(s=b(i.endContainer))?(j=i.cloneRange(),p.select(s.previousSibling,!0),p.collapse(),l=p.getRng(),j.setEnd(l.endContainer,l.endOffset),p.setRng(j)):(s=b(i.startContainer))&&(j=i.cloneRange(),j.setStart(s.nextSibling,0),p.setRng(j))),s&&((d=o.hasClass(s,"wpview-selection-before"))||(e=o.hasClass(s,"wpview-selection-after")))&&(e&&n===q.UP||d&&n===q.BACKSPACE?(s.previousSibling?b(s.previousSibling)?f(!1,s.previousSibling):o.isEmpty(s.previousSibling)&&n===q.BACKSPACE?o.remove(s.previousSibling):(p.select(s.previousSibling,!0),p.collapse()):f(!0,s),c.preventDefault()):!e||n!==q.DOWN&&n!==q.RIGHT?!d||n!==q.UP&&n!==q.LEFT?d&&n===q.DOWN?(s.nextSibling?b(s.nextSibling)?f(!0,s.nextSibling):p.setCursorLocation(s.nextSibling,0):f(!1,s),c.preventDefault()):e&&n===q.LEFT||d&&n===q.RIGHT?(h(s),c.preventDefault(),c.stopImmediatePropagation()):e&&n===q.BACKSPACE?(o.remove(s),c.preventDefault()):e?g(s):d&&g(s,!0):(s.previousSibling&&(b(s.previousSibling)?f(n===q.UP,s.previousSibling):(p.select(s.previousSibling,!0),p.collapse())),c.preventDefault()):(s.nextSibling&&(b(s.nextSibling)?f(n===q.RIGHT,s.nextSibling):p.setCursorLocation(s.nextSibling,0)),c.preventDefault()),n===q.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,h=c.keyCode,j=a.selection;if(k){if(c.metaKey||c.ctrlKey||h>=112&&123>=h)return void(!c.metaKey&&!c.ctrlKey||88!==h&&h!==q.BACKSPACE||(88===h?s=k:a.dom.remove(k)));if(d=b(j.getNode()),d!==k)return void i();h===q.LEFT?(f(!0,d),i()):h===q.UP?(d.previousSibling?b(d.previousSibling)?f(!0,d.previousSibling):(j.select(d.previousSibling,!0),j.collapse()):f(!0,d),i()):h===q.RIGHT?(f(!1,d),i()):h===q.DOWN?(d.nextSibling?b(d.nextSibling)?f(!1,d.nextSibling):j.setCursorLocation(d.nextSibling,0):f(!1,d),i()):h===q.ENTER?g(d):(h===q.DELETE||h===q.BACKSPACE)&&e.remove(k),c.preventDefault()}}),a.on("keydown",function(c){var d,e,g,h=a.selection;c.keyCode===q.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(g=b(d.previousSibling))&&(f(!1,g),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(g=b(d.previousSibling))&&(f(!1,g),c.preventDefault()))}),a.on("keyup",function(){s&&(a.dom.remove(s),s=!1)}),a.on("focus",function(){var c;o=!0,a.dom.addClass(a.getBody(),"has-focus"),t&&(c=b(a.getBody().firstChild))&&f(!0,c),t=!1}),a.on("blur",function(){o=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("nodechange",function(c){var d=a.dom,e=a.dom.select(".wpview-wrap"),g=c.element.className,h=b(c.element),i=m;if(m=!1,clearInterval(l),d.removeClass(e,"wpview-selection-before"),d.removeClass(e,"wpview-selection-after"),d.removeClass(e,"wpview-cursor-hide"),h&&a.selection.isCollapsed()&&o)if("wpview-selection-before"===g||"wpview-selection-after"===g){if(n=0,i===h.previousSibling)return void f(!0,h);if(i===h.nextSibling)return void f(!1,h);d.addClass(h,g),l=setInterval(function(){d.hasClass(h,"wpview-cursor-hide")?d.removeClass(h,"wpview-cursor-hide"):d.addClass(h,"wpview-cursor-hide")},500)}else k||n||(n++,f(!0,h))}),{getViewText:c,setViewText:d}}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index c659d003f6..b5aa08d618 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -241,8 +241,8 @@ audio { user-select: text; } -.wpview-wrap.wpview-selection-before:before, -.wpview-wrap.wpview-selection-after:before { +.has-focus .wpview-wrap.wpview-selection-before:before, +.has-focus .wpview-wrap.wpview-selection-after:before { content: ''; margin: 0; padding: 0; @@ -258,12 +258,12 @@ audio { opacity: 1; } -.wpview-wrap.wpview-selection-after:before { +.has-focus .wpview-wrap.wpview-selection-after:before { left: auto; right: -3px; } -.wpview-wrap.wpview-cursor-hide:before { +.has-focus .wpview-wrap.wpview-cursor-hide:before { opacity: 0; } diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 68762f6da1..1a5eeea0ef 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ diff --git a/wp-includes/version.php b/wp-includes/version.php index e752bb6354..099858897e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -18,7 +18,7 @@ $wp_db_version = 27916; * * @global string $tinymce_version */ -$tinymce_version = '4028-20140630'; +$tinymce_version = '4028-20140706'; /** * Holds the required PHP version