- // Remove marker attributes
- $( 'p[data-wpview-marker]', rootNode ).attr( 'data-wpview-marker', null );
- }
-
- editor.on( 'PreProcess', function( event ) {
- // Replace the view nodes with their text in the DOM clone.
- resetViews( event.node );
- }, true );
-
- editor.on( 'hide', function() {
- // Replace the view nodes with their text directly in the editor body.
- wp.mce.views.unbind();
- deselect();
- resetViews( editor.getBody() );
- });
-
- // Excludes arrow keys, delete, backspace, enter, space bar.
- // Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode
- function isSpecialKey( key ) {
- return ( ( key <= 47 && key !== VK.SPACEBAR && key !== VK.ENTER && key !== VK.DELETE && key !== VK.BACKSPACE && ( key < 37 || key > 40 ) ) ||
- key >= 224 || // OEM or non-printable
- ( key >= 144 && key <= 150 ) || // Num Lock, Scroll Lock, OEM
- ( key >= 91 && key <= 93 ) || // Windows keys
- ( key >= 112 && key <= 135 ) ); // F keys
- }
-
- // (De)select views when arrow keys are used to navigate the content of the editor.
- editor.on( 'keydown', function( event ) {
- var key = event.keyCode,
- dom = editor.dom,
- selection = editor.selection,
- node, view, cursorBefore, cursorAfter,
- range, clonedRange, tempRange;
-
- if ( selected ) {
- // Ignore key presses that involve the command or control key, but continue when in combination with backspace or v.
- // Also ignore the F# keys.
- if ( ( ( event.metaKey || event.ctrlKey ) && key !== VK.BACKSPACE && key !== 86 ) || ( key >= 112 && key <= 123 ) ) {
- // Remove the view when pressing cmd/ctrl+x on keyup, otherwise the browser can't copy the content.
- if ( ( event.metaKey || event.ctrlKey ) && key === 88 ) {
- toRemove = selected;
- }
- return;
- }