Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -531,6 +531,8 @@ |
532 | 532 | ], |
533 | 533 | 'prepareInsertion splits up paragraph when inserting a paragraph closing and opening into a paragraph' |
534 | 534 | ); |
| 535 | + |
| 536 | + // TODO add test cases for expected exceptions for bad offset and malformed input |
535 | 537 | } ); |
536 | 538 | |
537 | 539 | test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 10, function() { |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -722,8 +722,13 @@ |
723 | 723 | |
724 | 724 | var tx = new es.Transaction(), |
725 | 725 | insertedData = data, // may be cloned and modified |
726 | | - isStructuralLoc = es.DocumentModel.isStructuralOffset( this.data, offset ); |
| 726 | + isStructuralLoc = es.DocumentModel.isStructuralOffset( this.data, offset ), |
| 727 | + wrappingElementType; |
727 | 728 | |
| 729 | + if ( offset < 0 || offset > this.data.length ) { |
| 730 | + throw 'Offset ' + offset + ' out of bounds [0..' + this.data.length + ']'; |
| 731 | + } |
| 732 | + |
728 | 733 | if ( offset > 0 ) { |
729 | 734 | tx.pushRetain( offset ); |
730 | 735 | } |
— | — | @@ -732,7 +737,11 @@ |
733 | 738 | if ( isStructuralLoc ) { |
734 | 739 | insertedData = balance( insertedData ); |
735 | 740 | } else { |
736 | | - // TODO close and reopen the element the insertion point is in |
| 741 | + // We're inserting structure at a content location, |
| 742 | + // so we need to split up the wrapping element |
| 743 | + wrappingElementType = this.getNodeFromOffset( offset ).getElementType(); |
| 744 | + insertedData = [ { 'type': '/' + wrappingElementType }, { 'type': wrappingElementType } ]; |
| 745 | + es.insertIntoArray( insertedData, 1, data ); |
737 | 746 | } |
738 | 747 | } else { |
739 | 748 | if ( isStructuralLoc ) { |