r98133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98132‎ | r98133 | r98134 >
Date:14:53, 26 September 2011
Author:inez
Status:deferred
Tags:
Comment:
New implementation of select method in AggregateArray and new way of drawing and clearing selection for all implemented views
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.BlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ContentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockItemView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js
@@ -64,67 +64,58 @@
6565 return Math.max( 0, sum + this.length - 1 );
6666 };
6767
68 -es.AggregateArray.prototype.getCoverage = function( start, end ) {
69 - var result = { 'on': [], 'off': [] },
70 - sum = 0,
71 - len;
72 - for ( var i = 0, length = this.length; i < length; i++ ) {
73 - len = this[i].getLength();
74 - if ( sum >= start && sum + len < end ) {
75 - result.on.push( this[i] );
76 - } else {
77 - result.off.push( this[i] );
78 - }
79 - sum += len
80 - }
81 - return result;
82 -};
 68+es.AggregateArray.prototype.select = function( start, end, off ) {
 69+ var result = { 'on': [], 'off': [] },
 70+ left = 0,
 71+ right,
 72+ items = [],
 73+ off = off || false;
8374
84 -es.AggregateArray.prototype.select = function( start, end ) {
85 - // Support es.Range object as first argument
8675 if ( typeof start.from === 'number' && typeof start.to === 'number') {
8776 start.normalize();
8877 end = start.end;
8978 start = start.start;
9079 }
91 - var items = [];
92 - if ( this.length ) {
93 - var i = 0,
94 - length = this.length,
95 - left = 0,
96 - right,
97 - inside = false,
98 - from,
99 - to;
100 - while ( i < length ) {
101 - right = left + this[i].getLength() + 1;
102 - if ( inside ) {
103 - // Append items until we reach the end
104 - from = 0;
105 - to = Math.min( right - left - 1, end - left );
10680
107 - if ( from !== to ) {
108 - items.push( { 'item': this[i], 'from': from, 'to': to } );
109 - }
110 - if ( end >= left && end < right ) {
 81+ for ( var i = 0, length = this.length; i < length; i++ ) {
 82+ right = left + this[i].getLength() + 1;
 83+ if ( start >= left && start < right ) {
 84+ if ( end < right ) {
 85+ result.on.push( {
 86+ 'item': this[i],
 87+ 'from': start - left,
 88+ 'to': end - left
 89+ } );
 90+ if ( off === false ) {
11191 break;
11292 }
113 - } else if ( start >= left && start < right ) {
114 - inside = true;
115 - // Append first item
116 - from = start - left;
117 - //to = Math.min( right - 1, end - left );
118 - to = Math.min( right - left - 1, end - left );
119 - if ( from !== to ) {
120 - items.push( { 'item': this[i], 'from': from, 'to': to } );
121 - }
122 - if ( right >= end ) {
123 - break;
124 - }
 93+ } else {
 94+ result.on.push( {
 95+ 'item': this[i],
 96+ 'from': start - left,
 97+ 'to': right - left - 1
 98+ } );
12599 }
126 - left = right;
127 - i++;
 100+ } else if ( end >= left && end < right ) {
 101+ result.on.push( {
 102+ 'item': this[i],
 103+ 'from': 0,
 104+ 'to': end - left
 105+ } );
 106+ if ( off === false ) {
 107+ break;
 108+ }
 109+ } else if ( left >= start && right <= end ) {
 110+ result.on.push( {
 111+ 'item': this[i],
 112+ 'from': 0,
 113+ 'to': right - left - 1
 114+ } );
 115+ } else if( off === true ) {
 116+ result.off.push( this[i] );
128117 }
 118+ left = right;
129119 }
130 - return items;
131 -};
 120+
 121+ return result;
 122+};
\ No newline at end of file
Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockItemView.js
@@ -66,6 +66,10 @@
6767 this.contentView.drawSelection( range );
6868 };
6969
 70+es.ListBlockItemView.prototype.clearSelection = function() {
 71+ this.contentView.clearSelection();
 72+};
 73+
7074 /**
7175 * Gets length of contents.
7276 *
Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
@@ -49,14 +49,22 @@
5050 * @param range {es.Range} Range of content to draw selection around
5151 */
5252 es.ListBlockView.prototype.drawSelection = function( range ) {
53 - var selectedItems = this.items.select( range );
54 - for ( var i = 0; i < selectedItems.length; i++ ) {
55 - selectedItems[i].item.drawSelection(
56 - new es.Range( selectedItems[i].from, selectedItems[i].to )
57 - );
 53+ var views = this.items.select( range, null, true );
 54+
 55+ for ( var i = 0; i < views.on.length; i++ ) {
 56+ views.on[i].item.drawSelection( new es.Range( views.on[i].from, views.on[i].to ) );
5857 }
 58+ for ( var i = 0; i < views.off.length; i++ ) {
 59+ views.off[i].clearSelection();
 60+ }
5961 };
6062
 63+es.ListBlockView.prototype.clearSelection = function( range ) {
 64+ for ( var i = 0; i < this.items.length; i++ ) {
 65+ this.items[i].clearSelection();
 66+ }
 67+};
 68+
6169 /**
6270 * Render content.
6371 *
Index: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js
@@ -15,6 +15,20 @@
1616 };
1717
1818 /**
 19+ * Draw selection around a given range.
 20+ *
 21+ * @method
 22+ * @param range {es.Range} Range of content to draw selection around
 23+ */
 24+es.BlockView.prototype.drawSelection = function( range ) {
 25+ throw 'BlockView.drawSelection not implemented in this subclass.';
 26+};
 27+
 28+es.BlockView.prototype.clearSelection = function() {
 29+ throw 'BlockView.clearSelection not implemented in this subclass.';
 30+};
 31+
 32+/**
1933 * Render content.
2034 *
2135 * @method
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
@@ -249,6 +249,12 @@
250250 }
251251 };
252252
 253+es.ContentView.prototype.clearSelection = function() {
 254+ this.$rangeStart.hide();
 255+ this.$rangeFill.hide();
 256+ this.$rangeEnd.hide();
 257+};
 258+
253259 /**
254260 * Gets the index of the rendered line a given offset is within.
255261 *
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
@@ -78,14 +78,22 @@
7979 * @param range {es.Range} Range of content to draw selection around
8080 */
8181 es.TableBlockRowView.prototype.drawSelection = function( range ) {
82 - var selectedViews = this.items.select( range );
83 - for ( var i = 0; i < selectedViews.length; i++ ) {
84 - selectedViews[i].item.drawSelection(
85 - new es.Range( selectedViews[i].from, selectedViews[i].to )
86 - );
 82+ var views = this.items.select( range, null, true );
 83+
 84+ for ( var i = 0; i < views.on.length; i++ ) {
 85+ views.on[i].item.drawSelection( new es.Range( views.on[i].from, views.on[i].to ) );
8786 }
 87+ for ( var i = 0; i < views.off.length; i++ ) {
 88+ views.off[i].clearSelection();
 89+ }
8890 };
8991
 92+es.TableBlockRowView.prototype.clearSelection = function( range ) {
 93+ for ( var i = 0; i < this.items.length; i++ ) {
 94+ this.items[i].clearSelection();
 95+ }
 96+};
 97+
9098 /**
9199 * Gets length of contents.
92100 *
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
@@ -69,13 +69,13 @@
7070 * @param range {es.Range} Range of content to draw selection around
7171 */
7272 es.DocumentView.prototype.drawSelection = function( range ) {
73 - $('.editSurface-range').hide();
74 - var selectedViews = this.items.select( range );
75 - for ( var i = 0; i < selectedViews.length; i++ ) {
76 - selectedViews[i].item.drawSelection(
77 - new es.Range( selectedViews[i].from, selectedViews[i].to )
78 - );
 73+ var views = this.items.select( range, null, true );
 74+ for ( var i = 0; i < views.on.length; i++ ) {
 75+ views.on[i].item.drawSelection( new es.Range( views.on[i].from, views.on[i].to ) );
7976 }
 77+ for ( var i = 0; i < views.off.length; i++ ) {
 78+ views.off[i].clearSelection();
 79+ }
8080 };
8181
8282 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
@@ -69,6 +69,10 @@
7070 this.contentView.drawSelection( range );
7171 };
7272
 73+es.ParagraphBlockView.prototype.clearSelection = function( range ) {
 74+ this.contentView.clearSelection();
 75+};
 76+
7377 /**
7478 * Gets length of contents.
7579 *
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
@@ -87,16 +87,22 @@
8888 * @param range {es.Range} Range of content to draw selection around
8989 */
9090 es.TableBlockCellView.prototype.drawSelection = function( range ) {
91 - var selectedViews = this.items.select( range );
92 - for ( var i = 0; i < selectedViews.length; i++ ) {
93 - selectedViews[i].item.drawSelection(
94 - new es.Range( selectedViews[i].from, selectedViews[i].to )
95 - );
 91+ var views = this.items.select( range, null, true );
 92+
 93+ for ( var i = 0; i < views.on.length; i++ ) {
 94+ views.on[i].item.drawSelection( new es.Range( views.on[i].from, views.on[i].to ) );
9695 }
 96+ for ( var i = 0; i < views.off.length; i++ ) {
 97+ views.off[i].clearSelection();
 98+ }
9799 };
98100
 101+es.TableBlockCellView.prototype.clearSelection = function( range ) {
 102+ for ( var i = 0; i < this.items.length; i++ ) {
 103+ this.items[i].clearSelection();
 104+ }
 105+};
99106
100 -
101107 /**
102108 * Gets HTML rendering of block.
103109 *
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js
@@ -79,14 +79,22 @@
8080 * @param range {es.Range} Range of content to draw selection around
8181 */
8282 es.TableBlockView.prototype.drawSelection = function( range ) {
83 - var selectedViews = this.items.select( range );
84 - for ( var i = 0; i < selectedViews.length; i++ ) {
85 - selectedViews[i].item.drawSelection(
86 - new es.Range( selectedViews[i].from, selectedViews[i].to )
87 - );
 83+ var views = this.items.select( range, null, true );
 84+
 85+ for ( var i = 0; i < views.on.length; i++ ) {
 86+ views.on[i].item.drawSelection( new es.Range( views.on[i].from, views.on[i].to ) );
8887 }
 88+ for ( var i = 0; i < views.off.length; i++ ) {
 89+ views.off[i].clearSelection();
 90+ }
8991 };
9092
 93+es.TableBlockView.prototype.clearSelection = function( range ) {
 94+ for ( var i = 0; i < this.items.length; i++ ) {
 95+ this.items[i].clearSelection();
 96+ }
 97+};
 98+
9199 /**
92100 * Gets length of contents.
93101 *

Status & tagging log