Ticket #33300: 33300.3.patch
File 33300.3.patch, 3.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js
25 25 { start: '####', format: 'h4' }, 26 26 { start: '#####', format: 'h5' }, 27 27 { start: '######', format: 'h6' }, 28 { start: '>', format: 'blockquote' } 28 { start: '>', format: 'blockquote' }, 29 { regExp: /^(?:[*-]\s?){3,}$/, element: 'hr' } 29 30 ]; 30 31 31 32 var inlinePatterns = [ … … 37 38 ]; 38 39 39 40 var canUndo; 40 var refNode;41 var refPattern;42 41 var chars = []; 43 42 var zeroWidthSpaceNode; 44 43 … … 72 71 } 73 72 74 73 if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) { 75 watchEnter();74 enter(); 76 75 } 77 76 }, true ); 78 77 79 78 editor.on( 'keyup', function( event ) { 80 79 if ( event.keyCode === VK.SPACEBAR && ! event.ctrlKey && ! event.metaKey && ! event.altKey ) { 81 80 space(); 82 } else if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {83 enter();84 81 } else if ( event.keyCode > 47 && ! ( event.keyCode >= 91 && event.keyCode <= 93 ) ) { 85 82 inline(); 86 83 } … … 233 230 } ); 234 231 } 235 232 236 function watchEnter() {233 function enter() { 237 234 var rng = editor.selection.getRng(), 238 235 start = rng.startContainer, 239 236 node = firstTextNode( start ), … … 247 244 text = node.data; 248 245 249 246 while ( i-- ) { 250 if ( text.indexOf( enterPatterns[ i ].start ) === 0 ) { 251 pattern = enterPatterns[ i ]; 252 break; 253 } 247 if ( enterPatterns[ i ].start ) { 248 if ( text.indexOf( enterPatterns[ i ].start ) === 0 ) { 249 pattern = enterPatterns[ i ]; 250 break; 251 } 252 } else if ( enterPatterns[ i ].regExp ) { 253 if ( enterPatterns[ i ].regExp.test( text ) ) { 254 pattern = enterPatterns[ i ]; 255 break; 256 } 257 } 254 258 } 255 259 256 260 if ( ! pattern ) { … … 261 265 return; 262 266 } 263 267 264 refNode = node; 265 refPattern = pattern; 266 } 267 268 function ltrim( text ) { 269 return text ? text.replace( /^\s+/, '' ) : ''; 270 } 271 272 function enter() { 273 if ( refNode ) { 268 editor.once( 'keyup', function() { 274 269 editor.undoManager.add(); 275 270 276 271 editor.undoManager.transact( function() { 277 editor.formatter.apply( refPattern.format, {}, refNode ); 278 refNode.replaceData( 0, refNode.data.length, ltrim( refNode.data.slice( refPattern.start.length ) ) ); 272 if ( pattern.format ) { 273 editor.formatter.apply( pattern.format, {}, node ); 274 node.replaceData( 0, node.data.length, ltrim( node.data.slice( pattern.start.length ) ) ); 275 } else if ( pattern.element ) { 276 editor.getBody().replaceChild( document.createElement( pattern.element ), node.parentNode ); 277 } 279 278 } ); 280 279 281 280 // We need to wait for native events to be triggered. 282 281 setTimeout( function() { 283 282 canUndo = 'enter'; 284 283 } ); 285 } 284 } ); 285 } 286 286 287 refNode = null;288 re fPattern = null;287 function ltrim( text ) { 288 return text ? text.replace( /^\s+/, '' ) : ''; 289 289 } 290 290 } ); 291 291 } )( window.tinymce, window.setTimeout );