Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -547,6 +547,7 @@ |
548 | 548 | es.DocumentModel.prototype.prepareInsertion = function( offset, data ) { |
549 | 549 | var tx = new es.Transaction(); |
550 | 550 | /* |
| 551 | + * // Structural changes |
551 | 552 | * There are 2 basic types of locations the insertion point can be: |
552 | 553 | * Structural locations |
553 | 554 | * |<p>a</p><p>b</p> - Beginning of the document |
— | — | @@ -584,6 +585,7 @@ |
585 | 586 | es.DocumentModel.prototype.prepareRemoval = function( range ) { |
586 | 587 | var tx = new es.Transaction(); |
587 | 588 | /* |
| 589 | + * // Structural changes |
588 | 590 | * if ( The range spans structural elements ) { |
589 | 591 | * if ( The range partially overlaps structural elements ) { |
590 | 592 | * Add insertions to replace removed openings and closing to overlapped elements |
— | — | @@ -609,24 +611,34 @@ |
610 | 612 | |
611 | 613 | var i = range.start, |
612 | 614 | span = i, |
613 | | - annotating = this.data[i].type !== undefined; |
| 615 | + on = this.data[i].type !== undefined; |
614 | 616 | while ( i < range.end ) { |
615 | 617 | if ( this.data[i].type !== undefined ) { |
616 | | - // Structural |
617 | | - if ( annotating ) { |
| 618 | + // Don't annotate structural elements |
| 619 | + if ( on ) { |
618 | 620 | tx.pushStopAnnotating( method, annotation ); |
619 | 621 | span = 0; |
620 | | - annotating = false; |
| 622 | + on = false; |
621 | 623 | } |
622 | 624 | } else { |
623 | | - // Content |
624 | | - if ( !annotating ) { |
625 | | - if ( span ) { |
626 | | - tx.pushRetain( span ); |
| 625 | + var covered = es.DocumentModel.getIndexOfAnnotation( this.data[i] ) !== -1; |
| 626 | + if ( covered && method === 'set' || !covered && method === 'clear' ) { |
| 627 | + // Don't set/clear annotations on content that's already set/cleared |
| 628 | + if ( on ) { |
| 629 | + tx.pushStopAnnotating( method, annotation ); |
| 630 | + span = 0; |
| 631 | + on = false; |
627 | 632 | } |
628 | | - tx.pushStartAnnotating( method, annotation ); |
629 | | - span = 0; |
630 | | - annotating = true; |
| 633 | + } else { |
| 634 | + // Content |
| 635 | + if ( !on ) { |
| 636 | + if ( span ) { |
| 637 | + tx.pushRetain( span ); |
| 638 | + } |
| 639 | + tx.pushStartAnnotating( method, annotation ); |
| 640 | + span = 0; |
| 641 | + on = true; |
| 642 | + } |
631 | 643 | } |
632 | 644 | } |
633 | 645 | span++; |