r100984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100983‎ | r100984 | r100985 >
Date:15:28, 27 October 2011
Author:catrope
Status:deferred
Tags:
Comment:
prepareInsertion: Split up the wrapping element when inserting structure at a content location. This makes test #5 pass and #6 fail, as expected
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
@@ -531,6 +531,8 @@
532532 ],
533533 'prepareInsertion splits up paragraph when inserting a paragraph closing and opening into a paragraph'
534534 );
 535+
 536+ // TODO add test cases for expected exceptions for bad offset and malformed input
535537 } );
536538
537539 test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 10, function() {
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -722,8 +722,13 @@
723723
724724 var tx = new es.Transaction(),
725725 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;
727728
 729+ if ( offset < 0 || offset > this.data.length ) {
 730+ throw 'Offset ' + offset + ' out of bounds [0..' + this.data.length + ']';
 731+ }
 732+
728733 if ( offset > 0 ) {
729734 tx.pushRetain( offset );
730735 }
@@ -732,7 +737,11 @@
733738 if ( isStructuralLoc ) {
734739 insertedData = balance( insertedData );
735740 } 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 );
737746 }
738747 } else {
739748 if ( isStructuralLoc ) {

Status & tagging log