r99271 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99270‎ | r99271 | r99272 >
Date:21:56, 7 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Made es.DocumentModel.prepareContentAnnotation not set or clear already set or cleared annotations, making the transaction reversible.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -547,6 +547,7 @@
548548 es.DocumentModel.prototype.prepareInsertion = function( offset, data ) {
549549 var tx = new es.Transaction();
550550 /*
 551+ * // Structural changes
551552 * There are 2 basic types of locations the insertion point can be:
552553 * Structural locations
553554 * |<p>a</p><p>b</p> - Beginning of the document
@@ -584,6 +585,7 @@
585586 es.DocumentModel.prototype.prepareRemoval = function( range ) {
586587 var tx = new es.Transaction();
587588 /*
 589+ * // Structural changes
588590 * if ( The range spans structural elements ) {
589591 * if ( The range partially overlaps structural elements ) {
590592 * Add insertions to replace removed openings and closing to overlapped elements
@@ -609,24 +611,34 @@
610612
611613 var i = range.start,
612614 span = i,
613 - annotating = this.data[i].type !== undefined;
 615+ on = this.data[i].type !== undefined;
614616 while ( i < range.end ) {
615617 if ( this.data[i].type !== undefined ) {
616 - // Structural
617 - if ( annotating ) {
 618+ // Don't annotate structural elements
 619+ if ( on ) {
618620 tx.pushStopAnnotating( method, annotation );
619621 span = 0;
620 - annotating = false;
 622+ on = false;
621623 }
622624 } else {
623 - // Content
624 - if ( !annotating ) {
625 - if ( span ) {
626 - tx.pushRetain( span );
 625+ var covered = es.DocumentModel.getIndexOfAnnotation( this.data[i] ) !== -1;
 626+ if ( covered && method === 'set' || !covered && method === 'clear' ) {
 627+ // Don't set/clear annotations on content that's already set/cleared
 628+ if ( on ) {
 629+ tx.pushStopAnnotating( method, annotation );
 630+ span = 0;
 631+ on = false;
627632 }
628 - tx.pushStartAnnotating( method, annotation );
629 - span = 0;
630 - annotating = true;
 633+ } else {
 634+ // Content
 635+ if ( !on ) {
 636+ if ( span ) {
 637+ tx.pushRetain( span );
 638+ }
 639+ tx.pushStartAnnotating( method, annotation );
 640+ span = 0;
 641+ on = true;
 642+ }
631643 }
632644 }
633645 span++;

Status & tagging log