Ticket #26959: 26959-08.patch
File 26959-08.patch, 4.7 KB (added by , 11 years ago) |
---|
-
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
diff --git src/wp-includes/js/tinymce/plugins/wpview/plugin.js src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 48775f9..45321c4 100644
tinymce.PluginManager.add( 'wpview', function( editor ) { 86 86 editor.dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop ); 87 87 editor.dom.bind( selected, 'beforedeactivate focusin focusout', _stop ); 88 88 89 // Make sure that the editor is focused. 90 // It is possible that the editor is not focused when the mouse event fires 91 // without focus, the selection will not work properly. 92 editor.getBody().focus(); 93 89 94 // select the hidden div 90 95 editor.selection.select( clipboard, true ); 91 96 } … … tinymce.PluginManager.add( 'wpview', function( editor ) { 156 161 editor.selection.setCursorLocation( padNode, 0 ); 157 162 } 158 163 } 159 160 // refreshEmptyContentNode();161 164 }); 162 165 163 166 // Detect mouse down events that are adjacent to a view when a view is the first view or the last view … … tinymce.PluginManager.add( 'wpview', function( editor ) { 188 191 } 189 192 190 193 if ( padNode ) { 194 // Make sure that a selected view is deselected so that focus and selection are handled properly 195 deselect(); 196 editor.getBody().focus(); 191 197 editor.selection.setCursorLocation( padNode, 0 ); 192 198 } 193 199 } … … tinymce.PluginManager.add( 'wpview', function( editor ) { 298 304 299 305 editor.on( 'keydown', function( event ) { 300 306 var keyCode = event.keyCode, 301 view; 307 body = editor.getBody(), 308 view, padNode; 302 309 303 310 // If a view isn't selected, let the event go on its merry way. 304 311 if ( ! selected ) { … … tinymce.PluginManager.add( 'wpview', function( editor ) { 314 321 return; 315 322 } 316 323 317 // If the caret is not within the selected view, deselect the318 // view and bail.319 324 view = getParentView( editor.selection.getNode() ); 320 325 326 // If the caret is not within the selected view, deselect the 327 // view and bail. 321 328 if ( view !== selected ) { 322 329 deselect(); 323 330 return; 324 331 } 325 332 333 if ( keyCode === VK.LEFT || keyCode === VK.UP ) { 334 deselect(); 335 // Handle case where two views are stacked on top of one another 336 if ( isView( view.previousSibling ) ) { 337 select( view.previousSibling ); 338 // Handle case where view is the first node 339 } else if ( view.previousSibling === null ) { 340 padNode = createPadNode(); 341 body.insertBefore( padNode, body.firstChild ); 342 editor.selection.setCursorLocation( body.firstChild, 0 ); 343 // Handle default case 344 } else { 345 editor.selection.select( view.previousSibling, true ); 346 editor.selection.collapse(); 347 } 348 } 349 350 if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { 351 deselect(); 352 // Handle case where the next node is another wpview 353 if ( isView( view.nextSibling ) ) { 354 select( view.nextSibling ); 355 // Handle case were the view is that last node 356 } else if ( view.nextSibling === null ) { 357 padNode = createPadNode(); 358 body.appendChild( padNode ); 359 editor.selection.setCursorLocation( body.lastChild, 0 ); 360 // Handle default case where the next node is a non-wpview 361 } else { 362 editor.selection.setCursorLocation( view.nextSibling.firstChild, 0 ); 363 } 364 } 365 326 366 // If delete or backspace is pressed, delete the view. 327 367 if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { 328 368 editor.dom.remove( selected ); … … tinymce.PluginManager.add( 'wpview', function( editor ) { 331 371 event.preventDefault(); 332 372 }); 333 373 374 // Select and deselect views when arrow keys are used to navigate the content of the editor. 375 editor.on( 'keydown', function( event ) { 376 var keyCode = event.keyCode, 377 range = editor.selection.getRng(), 378 body = editor.getBody(), 379 node; 380 381 if ( range.collapsed !== true || event.metaKey || event.ctrlKey ) { 382 return; 383 } 384 385 if ( keyCode === VK.LEFT || keyCode === VK.UP ) { 386 node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode; 387 // The caret is directly after a wpview 388 if ( range.startOffset === 0 && isView( node.previousSibling ) ) { 389 select( node.previousSibling ); 390 event.preventDefault(); 391 } 392 } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { 393 node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode; 394 // The caret is directly before a wpview 395 if ( ( ( range.startOffset === 0 && ! range.endContainer.length ) || ( range.startOffset === range.endContainer.length ) ) && 396 isView( node.nextSibling ) ) { 397 select( node.nextSibling ); 398 event.preventDefault(); 399 } 400 } 401 }); 402 334 403 editor.on( 'keyup', function( event ) { 335 404 var padNode, 336 405 keyCode = event.keyCode,