r99489 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99488‎ | r99489 | r99490 >
Date:16:15, 11 October 2011
Author:catrope
Status:deferred
Tags:
Comment:
Merge duplicate code from r99452 and r99487 (communication snafu between me and Neil) and add another test for prepareRemoval()
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
@@ -357,6 +357,23 @@
358358 );
359359
360360 deepEqual(
 361+ documentModel.prepareRemoval( new es.Range( 15, 18 ) ),
 362+ [
 363+ { 'type': 'retain', 'length': 15 },
 364+ {
 365+ 'type': 'remove',
 366+ 'data': [
 367+ { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
 368+ 'b',
 369+ { 'type': '/listItem' }
 370+ ]
 371+ },
 372+ { 'type': 'retain', 'length': 10 }
 373+ ],
 374+ 'prepareRemoval removes entire elements'
 375+ );
 376+
 377+ deepEqual(
361378 documentModel.prepareInsertion( 1, ['d', 'e', 'f'] ),
362379 [
363380 { 'type': 'retain', 'length': 1 },
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -597,16 +597,12 @@
598598 tx.pushRemove( removed );
599599
600600 // Retain up to the end of the document
601 - tx.pushRetain( this.data.length - range.end );
602 -
603 - range.normalize();
604 -
605 - if ( range.start > 0 ) {
606 - tx.pushRetain( range.start );
 601+ if ( range.end < this.data.length ) {
 602+ tx.pushRetain( this.data.length - range.end );
607603 }
608 -
609 - var i = range.start;
610 - removeData = [];
 604+
 605+ /*
 606+ * Loop to detect structural changes:
611607 while ( i < range.end ) {
612608 var data = this.data[i];
613609 if ( data.type !== undefined ) {
@@ -617,7 +613,7 @@
618614 }
619615 i++;
620616 }
621 - tx.pushRemove( removeData );
 617+ */
622618
623619 /*
624620 * // Structural changes
@@ -634,9 +630,7 @@
635631 i++;
636632 }
637633 */
638 - if ( range.end < this.data.length ) {
639 - tx.pushRetain( this.data.length - range.end );
640 - }
 634+
641635 return tx;
642636 };
643637

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99452make prepareRemoval test pass (naively -- will add better test next)neilk00:24, 11 October 2011
r99487Naive version of prepareRemoval() that handles simple casescatrope16:08, 11 October 2011

Status & tagging log