r94188 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94187‎ | r94188 | r94189 >
Date:19:20, 10 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Deleting content across multiple items in lists with adopting orphaned items
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -75,51 +75,82 @@
7676 locationEnd = this.list.getLocationFromOffset( range.end );
7777
7878 if ( locationStart.item == locationEnd.item ) {
 79+
 80+ // delete content within one item
7981
8082 locationStart.item.content.remove(
8183 new es.Range( locationStart.offset, locationStart.offset + range.getLength() )
8284 );
8385
8486 } else {
85 - var contentToAppend = locationEnd.item.flow.content.getContent(
 87+
 88+ // delete content across multiple items
 89+
 90+ // delete selected content in first selected item
 91+ locationStart.item.content.remove(
8692 new es.Range(
 93+ locationStart.offset,
 94+ locationStart.item.content.getLength()
 95+ )
 96+ );
 97+
 98+ // grab not selected content from last selected item..
 99+ var toAppend = locationEnd.item.content.getContent(
 100+ new es.Range(
87101 locationEnd.offset,
88 - locationEnd.item.flow.content.getLength()
 102+ locationEnd.item.content.getLength()
89103 )
90104 );
91 - locationStart.item.flow.content.remove(
92 - new es.Range( locationStart.offset, locationStart.item.flow.content.getLength() )
93 - );
94 - locationStart.item.flow.content.insert( locationStart.offset, contentToAppend.data );
 105+
 106+ // ..and insert it at the end of first selected item
 107+ locationStart.item.content.insert( locationStart.offset, toAppend.data );
95108
96 - var itemsToDelete;
 109+ var toDelete = [],
 110+ toAdopt = [],
 111+ newParents = [],
 112+ toDeleteCollecting = false,
 113+ toAdoptCollecting = false;
 114+
97115 this.traverseItems( function( item, index ) {
98 - if ( $.isArray( itemsToDelete ) ) {
99 - itemsToDelete.push( item );
 116+
 117+ if ( toDeleteCollecting === false && toDelete.length === 0 ) {
 118+ newParents[ item.getLevel() ] = item;
100119 }
101 - if ( item == locationEnd.item ) {
102 - return false;
 120+
 121+ if ( toDeleteCollecting ) {
 122+ toDelete.push( item );
103123 }
 124+
104125 if ( item == locationStart.item ) {
105 - itemsToDelete = [];
 126+ toDeleteCollecting = true;
 127+ }
 128+
 129+ if ( item == locationEnd.item ) {
 130+ toDeleteCollecting = false;
 131+ toAdoptCollecting = true;
 132+ return true;
106133 }
107 - } );
108134
109 - for ( var i = itemsToDelete.length - 1; i >= 0; i-- ) {
110 - if ( itemsToDelete[i].getLength() - 1 === itemsToDelete[i].flow.content.getLength() ) {
111 - itemsToDelete[i].list.remove(itemsToDelete[i]);
112 - } else {
113 - itemsToDelete[i].flow.content.remove( new es.Range( 0, itemsToDelete[i].flow.content.getLength() ) );
 135+ if ( toAdoptCollecting ) {
 136+ if( toDelete.indexOf ( item.list.item ) !== -1 ) {
 137+ toAdopt.push( item );
 138+ }
114139 }
115 - }
116140
117 - /*
118 - var start = locationEnd.item;
119 - while(start) {
120 - start = start.list.item;
121 - console.log("-")
 141+ } );
 142+
 143+ var toAdoptLevel,
 144+ newParent;
 145+
 146+ for ( var i = toAdopt.length - 1; i >= 0; i-- ) {
 147+ toAdoptLevel = toAdopt[i].getLevel();
 148+ newParent = newParents[ toAdoptLevel ] ? newParents[ toAdoptLevel ] : newParents[ newParents.length - 1 ];
 149+ newParent.lists[0].prepend( toAdopt[i] );
122150 }
123 - */
 151+
 152+ for ( var i = toDelete.length - 1; i >= 0; i-- ) {
 153+ toDelete[i].list.remove(toDelete[i]);
 154+ }
124155 }
125156 };
126157

Status & tagging log