Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -346,16 +346,21 @@ |
347 | 347 | break; |
348 | 348 | case 13: // Enter |
349 | 349 | if ( this.selection.from === this.selection.to ) { |
350 | | - var node = this.documentView.getNodeFromOffset( this.selection.to, false ), |
| 350 | + var tx, |
| 351 | + node = this.documentView.getNodeFromOffset( this.selection.to, false ), |
351 | 352 | nodeOffset = this.documentView.getOffsetFromNode( node, false ); |
352 | | - |
353 | | - if ( nodeOffset + node.getContentLength() + 1 === this.selection.to && node === es.DocumentViewNode.getSplitableNode( node ) ) { |
354 | | - var tx = this.documentView.model.prepareInsertion( |
| 353 | + |
| 354 | + if ( |
| 355 | + nodeOffset + node.getContentLength() + 1 === this.selection.to && |
| 356 | + node === es.DocumentViewNode.getSplitableNode( node ) |
| 357 | + ) { |
| 358 | + tx = this.documentView.model.prepareInsertion( |
355 | 359 | nodeOffset + node.getElementLength(), |
356 | 360 | [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ] |
357 | 361 | ); |
358 | 362 | this.documentView.model.commit( tx ); |
359 | | - this.selection.from = this.selection.to = nodeOffset + node.getElementLength() + 1; |
| 363 | + this.selection.from = this.selection.to = |
| 364 | + nodeOffset + node.getElementLength() + 1; |
360 | 365 | this.showCursor(); |
361 | 366 | } else { |
362 | 367 | var stack = [], |
— | — | @@ -363,20 +368,28 @@ |
364 | 369 | |
365 | 370 | es.DocumentNode.traverseUpstream( node, function( node ) { |
366 | 371 | var elementType = node.model.getElementType(); |
367 | | - if ( splitable === true && es.DocumentView.splitRules[ elementType ].children === true ) { |
| 372 | + if ( |
| 373 | + splitable === true && |
| 374 | + es.DocumentView.splitRules[ elementType ].children === true |
| 375 | + ) { |
368 | 376 | return false; |
369 | 377 | } |
370 | 378 | stack.splice( |
371 | 379 | stack.length / 2, |
372 | 380 | 0, |
373 | 381 | { 'type': '/' + elementType }, |
374 | | - { 'type': elementType, 'attributes': es.copyObject( node.model.element.attributes ) } |
| 382 | + { |
| 383 | + 'type': elementType, |
| 384 | + 'attributes': es.copyObject( node.model.element.attributes ) |
| 385 | + } |
375 | 386 | ); |
376 | 387 | splitable = es.DocumentView.splitRules[ elementType ].self; |
377 | 388 | } ); |
378 | | - var tx = this.documentView.model.prepareInsertion( this.selection.to, stack ); |
| 389 | + tx = this.documentView.model.prepareInsertion( this.selection.to, stack ); |
379 | 390 | this.documentView.model.commit( tx ); |
380 | | - this.selection.from = this.selection.to = this.documentView.getModel().getRelativeContentOffset( this.selection.to, 1 ); |
| 391 | + this.selection.from = this.selection.to = |
| 392 | + this.documentView.getModel() |
| 393 | + .getRelativeContentOffset( this.selection.to, 1 ); |
381 | 394 | this.showCursor(); |
382 | 395 | } |
383 | 396 | } |
— | — | @@ -410,27 +423,32 @@ |
411 | 424 | }; |
412 | 425 | |
413 | 426 | es.SurfaceView.prototype.handleDelete = function( backspace ) { |
| 427 | + var sourceOffset, |
| 428 | + targetOffset, |
| 429 | + sourceSplitableNode, |
| 430 | + targetSplitableNode, |
| 431 | + tx; |
414 | 432 | if ( this.selection.from === this.selection.to ) { |
415 | 433 | if ( backspace ) { |
416 | | - var sourceOffset = this.selection.to, |
417 | | - targetOffset = this.documentView.getModel().getRelativeContentOffset( |
418 | | - sourceOffset, |
419 | | - -1 |
420 | | - ); |
| 434 | + sourceOffset = this.selection.to; |
| 435 | + targetOffset = this.documentView.getModel().getRelativeContentOffset( |
| 436 | + sourceOffset, |
| 437 | + -1 |
| 438 | + ); |
421 | 439 | } else { |
422 | | - var sourceOffset = this.documentView.getModel().getRelativeContentOffset( |
423 | | - this.selection.to, |
424 | | - 1 |
425 | | - ), |
426 | | - targetOffset = this.selection.to; |
| 440 | + sourceOffset = this.documentView.getModel().getRelativeContentOffset( |
| 441 | + this.selection.to, |
| 442 | + 1 |
| 443 | + ); |
| 444 | + targetOffset = this.selection.to; |
427 | 445 | } |
428 | 446 | |
429 | 447 | var sourceNode = this.documentView.getNodeFromOffset( sourceOffset, false ), |
430 | 448 | targetNode = this.documentView.getNodeFromOffset( targetOffset, false ); |
431 | 449 | |
432 | 450 | if ( sourceNode.model.getElementType() === targetNode.model.getElementType() ) { |
433 | | - var sourceSplitableNode = es.DocumentViewNode.getSplitableNode( sourceNode ), |
434 | | - targetSplitableNode = es.DocumentViewNode.getSplitableNode( targetNode ); |
| 451 | + sourceSplitableNode = es.DocumentViewNode.getSplitableNode( sourceNode ); |
| 452 | + targetSplitableNode = es.DocumentViewNode.getSplitableNode( targetNode ); |
435 | 453 | } |
436 | 454 | |
437 | 455 | this.selection.from = this.selection.to = targetOffset; |
— | — | @@ -439,12 +457,12 @@ |
440 | 458 | if ( sourceNode === targetNode || |
441 | 459 | ( typeof sourceSplitableNode !== 'undefined' && |
442 | 460 | sourceSplitableNode.getParent() === targetSplitableNode.getParent() ) ) { |
443 | | - var tx = this.documentView.model.prepareRemoval( |
| 461 | + tx = this.documentView.model.prepareRemoval( |
444 | 462 | new es.Range( targetOffset, sourceOffset ) |
445 | 463 | ); |
446 | 464 | this.documentView.model.commit ( tx ); |
447 | 465 | } else { |
448 | | - var tx = this.documentView.model.prepareInsertion( |
| 466 | + tx = this.documentView.model.prepareInsertion( |
449 | 467 | targetOffset, sourceNode.model.getContent() |
450 | 468 | ); |
451 | 469 | this.documentView.model.commit( tx ); |
— | — | @@ -465,7 +483,7 @@ |
466 | 484 | } |
467 | 485 | } else { |
468 | 486 | // selection removal |
469 | | - var tx = this.documentView.model.prepareRemoval( this.selection ); |
| 487 | + tx = this.documentView.model.prepareRemoval( this.selection ); |
470 | 488 | this.documentView.model.commit( tx ); |
471 | 489 | this.documentView.clearSelection(); |
472 | 490 | this.selection.from = this.selection.to = this.selection.start; |
— | — | @@ -477,14 +495,15 @@ |
478 | 496 | var val = this.$input.val(); |
479 | 497 | this.$input.val( '' ); |
480 | 498 | if ( val.length > 0 ) { |
| 499 | + var tx; |
481 | 500 | if ( this.selection.from != this.selection.to ) { |
482 | | - var tx = this.documentView.model.prepareRemoval( this.selection ); |
| 501 | + tx = this.documentView.model.prepareRemoval( this.selection ); |
483 | 502 | this.documentView.model.commit( tx ); |
484 | 503 | this.documentView.clearSelection(); |
485 | | - this.selection.from = this.selection.to = Math.min( this.selection.from, this.selection.to ); |
| 504 | + this.selection.from = this.selection.to = |
| 505 | + Math.min( this.selection.from, this.selection.to ); |
486 | 506 | } |
487 | | - |
488 | | - var tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') ); |
| 507 | + tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') ); |
489 | 508 | this.documentView.model.commit ( tx ); |
490 | 509 | this.selection.from += val.length; |
491 | 510 | this.selection.to += val.length; |
— | — | @@ -503,7 +522,8 @@ |
504 | 523 | this.cursor.initialLeft = null; |
505 | 524 | } |
506 | 525 | |
507 | | - var to; |
| 526 | + var to, |
| 527 | + offset; |
508 | 528 | |
509 | 529 | switch ( direction ) { |
510 | 530 | case 'left': |
— | — | @@ -511,7 +531,6 @@ |
512 | 532 | switch ( unit ) { |
513 | 533 | case 'char': |
514 | 534 | case 'word': |
515 | | - var offset; |
516 | 535 | if ( this.keyboard.keys.shift || this.selection.from === this.selection.to ) { |
517 | 536 | offset = this.selection.to; |
518 | 537 | } else { |
— | — | @@ -531,7 +550,7 @@ |
532 | 551 | } |
533 | 552 | break; |
534 | 553 | case 'line': |
535 | | - var offset = this.cursor.initialBias ? |
| 554 | + offset = this.cursor.initialBias ? |
536 | 555 | this.documentView.getModel().getRelativeContentOffset( |
537 | 556 | this.selection.to, |
538 | 557 | -1) : |
— | — | @@ -579,13 +598,18 @@ |
580 | 599 | step = direction === 'up' ? -5 : 5, |
581 | 600 | top = this.$.position().top; |
582 | 601 | |
583 | | - this.cursor.initialBias = position.left > this.documentView.getNodeFromOffset( this.selection.to, false ).contentView.$.offset().left; |
| 602 | + this.cursor.initialBias = position.left > this.documentView.getNodeFromOffset( |
| 603 | + this.selection.to, false |
| 604 | + ).contentView.$.offset().left; |
584 | 605 | |
585 | 606 | do { |
586 | 607 | fakePosition.top += ++i * step; |
587 | 608 | if ( fakePosition.top < top ) { |
588 | 609 | break; |
589 | | - } else if (fakePosition.top > top + this.dimensions.height + this.dimensions.scrollTop ) { |
| 610 | + } else if ( |
| 611 | + fakePosition.top > top + this.dimensions.height + |
| 612 | + this.dimensions.scrollTop |
| 613 | + ) { |
590 | 614 | break; |
591 | 615 | } |
592 | 616 | fakePosition = this.documentView.getRenderedPositionFromOffset( |