Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -502,11 +502,43 @@ |
503 | 503 | test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 6, function() { |
504 | 504 | var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
505 | 505 | |
| 506 | + var elementAttributeChange = documentModel.prepareElementAttributeChange( |
| 507 | + 0, 'set', 'test', 1 |
| 508 | + ); |
| 509 | + |
| 510 | + // Test 1 |
| 511 | + documentModel.commit( elementAttributeChange ); |
| 512 | + deepEqual( |
| 513 | + documentModel.getData( new es.Range( 0, 5 ) ), |
| 514 | + [ |
| 515 | + { 'type': 'paragraph', 'attributes': { 'test': 1 } }, |
| 516 | + 'a', |
| 517 | + ['b', { 'type': 'bold', 'hash': '#bold' }], |
| 518 | + ['c', { 'type': 'italic', 'hash': '#italic' }], |
| 519 | + { 'type': '/paragraph' } |
| 520 | + ], |
| 521 | + 'commit applies an element attribute change transaction to the content' |
| 522 | + ); |
| 523 | + |
| 524 | + // Test 2 |
| 525 | + documentModel.rollback( elementAttributeChange ); |
| 526 | + deepEqual( |
| 527 | + documentModel.getData( new es.Range( 0, 5 ) ), |
| 528 | + [ |
| 529 | + { 'type': 'paragraph' }, |
| 530 | + 'a', |
| 531 | + ['b', { 'type': 'bold', 'hash': '#bold' }], |
| 532 | + ['c', { 'type': 'italic', 'hash': '#italic' }], |
| 533 | + { 'type': '/paragraph' } |
| 534 | + ], |
| 535 | + 'rollback reverses the effect of an element attribute change transaction on the content' |
| 536 | + ); |
| 537 | + |
506 | 538 | var contentAnnotation = documentModel.prepareContentAnnotation( |
507 | 539 | new es.Range( 1, 4 ), 'set', { 'type': 'bold' } |
508 | 540 | ); |
509 | 541 | |
510 | | - // Test 1 |
| 542 | + // Test 3 |
511 | 543 | documentModel.commit( contentAnnotation ); |
512 | 544 | deepEqual( |
513 | 545 | documentModel.getData( new es.Range( 0, 5 ) ), |
— | — | @@ -520,7 +552,7 @@ |
521 | 553 | 'commit applies a content annotation transaction to the content' |
522 | 554 | ); |
523 | 555 | |
524 | | - // Test 2 |
| 556 | + // Test 4 |
525 | 557 | documentModel.rollback( contentAnnotation ); |
526 | 558 | deepEqual( |
527 | 559 | documentModel.getData( new es.Range( 0, 5 ) ), |
— | — | @@ -536,7 +568,7 @@ |
537 | 569 | |
538 | 570 | var insertion = documentModel.prepareInsertion( 4, ['d'] ); |
539 | 571 | |
540 | | - // Test 3 |
| 572 | + // Test 5 |
541 | 573 | documentModel.commit( insertion ); |
542 | 574 | deepEqual( |
543 | 575 | documentModel.getData( new es.Range( 0, 6 ) ), |
— | — | @@ -551,7 +583,7 @@ |
552 | 584 | 'commit applies an insertion transaction to the content' |
553 | 585 | ); |
554 | 586 | |
555 | | - // Test 4 |
| 587 | + // Test 6 |
556 | 588 | documentModel.rollback( insertion ); |
557 | 589 | deepEqual( |
558 | 590 | documentModel.getData( new es.Range( 0, 5 ) ), |
— | — | @@ -567,7 +599,7 @@ |
568 | 600 | |
569 | 601 | var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) ); |
570 | 602 | |
571 | | - // Test 5 |
| 603 | + // Test 7 |
572 | 604 | documentModel.commit( removal ); |
573 | 605 | deepEqual( |
574 | 606 | documentModel.getData( new es.Range( 0, 3 ) ), |
— | — | @@ -579,7 +611,7 @@ |
580 | 612 | 'commit applies a removal transaction to the content' |
581 | 613 | ); |
582 | 614 | |
583 | | - // Test 6 |
| 615 | + // Test 8 |
584 | 616 | documentModel.rollback( removal ); |
585 | 617 | deepEqual( |
586 | 618 | documentModel.getData( new es.Range( 0, 5 ) ), |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -93,15 +93,15 @@ |
94 | 94 | if ( element.type === undefined ) { |
95 | 95 | throw 'Invalid element error. Can not set attributes on non-element data.'; |
96 | 96 | } |
97 | | - if ( op.method === 'set' || ( op.method === 'clear' && invert ) ) { |
| 97 | + if ( ( op.method === 'set' && !invert ) || ( op.method === 'clear' && invert ) ) { |
98 | 98 | // Automatically initialize attributes object |
99 | 99 | if ( !element.attributes ) { |
100 | 100 | element.attributes = {}; |
101 | 101 | } |
102 | | - element.attributes[op.name] = op.value; |
103 | | - } else if ( op.method === 'clear' || ( op.method === 'set' && invert ) ) { |
| 102 | + element.attributes[op.key] = op.value; |
| 103 | + } else if ( ( op.method === 'clear' && !invert ) || ( op.method === 'set' && invert ) ) { |
104 | 104 | if ( element.attributes ) { |
105 | | - delete element.attributes[op.name]; |
| 105 | + delete element.attributes[op.key]; |
106 | 106 | } |
107 | 107 | // Automatically clean up attributes object |
108 | 108 | var empty = true; |