Changeset 27582
- Timestamp:
- 03/18/2014 04:56:27 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js
r27544 r27582 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 ); … … 157 162 } 158 163 } 159 160 // refreshEmptyContentNode();161 164 }); 162 165 … … 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 } … … 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. … … 315 322 } 316 323 324 view = getParentView( editor.selection.getNode() ); 325 317 326 // If the caret is not within the selected view, deselect the 318 327 // view and bail. 319 view = getParentView( editor.selection.getNode() );320 321 328 if ( view !== selected ) { 322 329 deselect(); … … 324 331 } 325 332 326 // If delete or backspace is pressed, delete the view. 327 if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { 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 } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { 349 deselect(); 350 // Handle case where the next node is another wpview 351 if ( isView( view.nextSibling ) ) { 352 select( view.nextSibling ); 353 // Handle case were the view is that last node 354 } else if ( view.nextSibling === null ) { 355 padNode = createPadNode(); 356 body.appendChild( padNode ); 357 editor.selection.setCursorLocation( body.lastChild, 0 ); 358 // Handle default case where the next node is a non-wpview 359 } else { 360 editor.selection.setCursorLocation( view.nextSibling.firstChild, 0 ); 361 } 362 } else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { 363 // If delete or backspace is pressed, delete the view. 328 364 editor.dom.remove( selected ); 329 365 } 330 366 331 367 event.preventDefault(); 368 }); 369 370 // Select and deselect views when arrow keys are used to navigate the content of the editor. 371 editor.on( 'keydown', function( event ) { 372 var keyCode = event.keyCode, 373 range = editor.selection.getRng(), 374 body = editor.getBody(), 375 node; 376 377 if ( ! range.collapsed || event.metaKey || event.ctrlKey ) { 378 return; 379 } 380 381 if ( keyCode === VK.LEFT || keyCode === VK.UP ) { 382 node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode; 383 // The caret is directly after a wpview 384 if ( range.startOffset === 0 && isView( node.previousSibling ) ) { 385 select( node.previousSibling ); 386 event.preventDefault(); 387 } 388 } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { 389 node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode; 390 // The caret is directly before a wpview 391 if ( ( ( range.startOffset === 0 && ! range.endContainer.length ) || ( range.startOffset === range.endContainer.length ) ) && 392 isView( node.nextSibling ) ) { 393 select( node.nextSibling ); 394 event.preventDefault(); 395 } 396 } 332 397 }); 333 398
Note: See TracChangeset
for help on using the changeset viewer.