| 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 ) ) { |
| | 383 | if ( keyCode === VK.UP || keyCode === VK.LEFT ) { |
| | 384 | if ( keyCode === VK.LEFT && ( ! range.collapsed || range.startOffset !== 0 ) ) { |
| | 385 | // Not at the beginning of the current range |
| | 386 | return; |
| | 387 | } |
| | 388 | |
| | 389 | node = dom.getParent( startNode, dom.isBlock ); |
| | 390 | |
| | 391 | if ( ! node ) { |
| | 392 | return; |
| | 393 | } |
| | 394 | |
| | 395 | while ( node && node.parentNode !== body ) { |
| | 396 | if ( node.previousSibling ) { |
| | 397 | // The caret will be in another element |
| | 398 | return; |
| | 399 | } |
| | 400 | |
| | 401 | node = node.parentNode; |
| | 402 | } |
| | 403 | |
| | 404 | if ( isView( node.previousSibling ) ) { |
| 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 ) ) { |
| | 408 | } else if ( keyCode === VK.DOWN || keyCode === VK.RIGHT ) { |
| | 409 | node = dom.getParent( startNode, dom.isBlock ); |
| | 410 | |
| | 411 | if ( ! node ) { |
| | 412 | return; |
| | 413 | } |
| | 414 | |
| | 415 | if ( keyCode === VK.RIGHT ) { |
| | 416 | container = range.endContainer; |
| | 417 | |
| | 418 | if ( ! range.collapsed || ( range.startOffset === 0 && container.length ) || |
| | 419 | container.nextSibling || |
| | 420 | ( container.nodeType === 3 && range.startOffset !== container.length ) ) { // Not at the end of the current range |
| | 421 | |
| | 422 | return; |
| | 423 | } |
| | 424 | |
| | 425 | // In a child element |
| | 426 | while ( container && container !== node && container !== body ) { |
| | 427 | if ( container.nextSibling ) { |
| | 428 | return; |
| | 429 | } |
| | 430 | container = container.parentNode; |
| | 431 | } |
| | 432 | } |
| | 433 | |
| | 434 | while ( node && node.parentNode !== body ) { |
| | 435 | if ( node.nextSibling ) { |
| | 436 | // The caret will be in another element |
| | 437 | return; |
| | 438 | } |
| | 439 | |
| | 440 | node = node.parentNode; |
| | 441 | } |
| | 442 | |
| | 443 | if ( isView( node.nextSibling ) ) { |