Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -600,17 +600,56 @@ |
601 | 601 | * @returns {es.Transaction} |
602 | 602 | */ |
603 | 603 | es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, annotation ) { |
604 | | - // |
| 604 | + var tx = new es.Transaction(); |
| 605 | + range.normalize(); |
| 606 | + |
| 607 | + var i = range.start, |
| 608 | + span = i, |
| 609 | + annotating = this.data[i].type !== undefined; |
| 610 | + while ( i < range.end ) { |
| 611 | + if ( this.data[i].type !== undefined ) { |
| 612 | + // Structural |
| 613 | + if ( annotating ) { |
| 614 | + tx.pushStopAnnotating( method, annotation ); |
| 615 | + span = 0; |
| 616 | + annotating = false; |
| 617 | + } |
| 618 | + } else { |
| 619 | + // Content |
| 620 | + if ( !annotating ) { |
| 621 | + if ( span ) { |
| 622 | + tx.pushRetain( span ); |
| 623 | + } |
| 624 | + tx.pushStartAnnotating( method, annotation ); |
| 625 | + span = 0; |
| 626 | + annotating = true; |
| 627 | + } |
| 628 | + } |
| 629 | + span++; |
| 630 | + } |
| 631 | + if ( range.end < this.data.length ) { |
| 632 | + tx.pushRetain( this.data.length - range.end ); |
| 633 | + } |
| 634 | + return tx; |
605 | 635 | }; |
606 | 636 | |
607 | 637 | /** |
608 | | - * Generates a transaction which changes attributes on an element at a given index. |
| 638 | + * Generates a transaction which changes attributes on an element at a given offset. |
609 | 639 | * |
610 | 640 | * @method |
611 | 641 | * @returns {es.Transaction} |
612 | 642 | */ |
613 | | -es.DocumentModel.prototype.prepareElementAttributeChange = function( index, method, annotation ) { |
614 | | - // |
| 643 | +es.DocumentModel.prototype.prepareElementAttributeChange = function( offset, method, key, value ) { |
| 644 | + var tx = new es.Transaction(); |
| 645 | + if ( offset ) { |
| 646 | + tx.pushRetain( offset ); |
| 647 | + } |
| 648 | + if ( this.data[offset].type !== undefined ) { |
| 649 | + tx.pushChangeElementAttribute( method, key, value ); |
| 650 | + } |
| 651 | + if ( offset < this.data.length ) { |
| 652 | + tx.pushRetain( this.data.length - offset ); |
| 653 | + } |
615 | 654 | }; |
616 | 655 | |
617 | 656 | /** |
Index: trunk/parsers/wikidom/lib/hype/es.Transaction.js |
— | — | @@ -32,56 +32,29 @@ |
33 | 33 | } ); |
34 | 34 | }; |
35 | 35 | |
36 | | -es.Transaction.prototype.pushSetElementAttribute( key, value ) { |
| 36 | +es.Transaction.prototype.pushChangeElementAttribute( method, key, value ) { |
37 | 37 | this.push( { |
38 | 38 | 'type': 'attribute', |
39 | | - 'method': 'set', |
| 39 | + 'method': method, |
40 | 40 | 'key': key, |
41 | 41 | 'value': value |
42 | 42 | } ); |
43 | 43 | }; |
44 | 44 | |
45 | | -es.Transaction.prototype.pushClearElementAttribute( key, value ) { |
| 45 | +es.Transaction.prototype.pushStartAnnotating( method, annotation ) { |
46 | 46 | this.push( { |
47 | | - 'type': 'attribute', |
48 | | - 'method': 'clear', |
49 | | - 'key': key, |
50 | | - 'value': value |
51 | | - } ); |
52 | | -}; |
53 | | - |
54 | | -es.Transaction.prototype.pushStartSettingAnnotation( annotation ) { |
55 | | - this.push( { |
56 | 47 | 'type': 'annotate', |
57 | | - 'method': 'set', |
| 48 | + 'method': method, |
58 | 49 | 'bias': 'start', |
59 | 50 | 'annotation': annotation |
60 | 51 | } ); |
61 | 52 | }; |
62 | 53 | |
63 | | -es.Transaction.prototype.pushStopSettingAnnotation( annotation ) { |
| 54 | +es.Transaction.prototype.pushStopAnnotating( method, annotation ) { |
64 | 55 | this.push( { |
65 | 56 | 'type': 'annotate', |
66 | | - 'method': 'set', |
| 57 | + 'method': method, |
67 | 58 | 'bias': 'stop', |
68 | 59 | 'annotation': annotation |
69 | 60 | } ); |
70 | 61 | }; |
71 | | - |
72 | | -es.Transaction.prototype.pushStartClearingAnnotation( annotation ) { |
73 | | - this.push( { |
74 | | - 'type': 'annotate', |
75 | | - 'method': 'clear', |
76 | | - 'bias': 'start', |
77 | | - 'annotation': annotation |
78 | | - } ); |
79 | | -}; |
80 | | - |
81 | | -es.Transaction.prototype.pushStopClearingAnnotation( annotation ) { |
82 | | - this.push( { |
83 | | - 'type': 'annotate', |
84 | | - 'method': 'clear', |
85 | | - 'bias': 'stop', |
86 | | - 'annotation': annotation |
87 | | - } ); |
88 | | -}; |