Index: trunk/parsers/wikidom/lib/synth/bases/es.AggregateArray.js |
— | — | @@ -64,67 +64,58 @@ |
65 | 65 | return Math.max( 0, sum + this.length - 1 ); |
66 | 66 | }; |
67 | 67 | |
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; |
83 | 74 | |
84 | | -es.AggregateArray.prototype.select = function( start, end ) { |
85 | | - // Support es.Range object as first argument |
86 | 75 | if ( typeof start.from === 'number' && typeof start.to === 'number') { |
87 | 76 | start.normalize(); |
88 | 77 | end = start.end; |
89 | 78 | start = start.start; |
90 | 79 | } |
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 ); |
106 | 80 | |
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 ) { |
111 | 91 | break; |
112 | 92 | } |
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 | + } ); |
125 | 99 | } |
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] ); |
128 | 117 | } |
| 118 | + left = right; |
129 | 119 | } |
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 @@ |
67 | 67 | this.contentView.drawSelection( range ); |
68 | 68 | }; |
69 | 69 | |
| 70 | +es.ListBlockItemView.prototype.clearSelection = function() { |
| 71 | + this.contentView.clearSelection(); |
| 72 | +}; |
| 73 | + |
70 | 74 | /** |
71 | 75 | * Gets length of contents. |
72 | 76 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js |
— | — | @@ -49,14 +49,22 @@ |
50 | 50 | * @param range {es.Range} Range of content to draw selection around |
51 | 51 | */ |
52 | 52 | 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 ) ); |
58 | 57 | } |
| 58 | + for ( var i = 0; i < views.off.length; i++ ) { |
| 59 | + views.off[i].clearSelection(); |
| 60 | + } |
59 | 61 | }; |
60 | 62 | |
| 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 | + |
61 | 69 | /** |
62 | 70 | * Render content. |
63 | 71 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js |
— | — | @@ -15,6 +15,20 @@ |
16 | 16 | }; |
17 | 17 | |
18 | 18 | /** |
| 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 | +/** |
19 | 33 | * Render content. |
20 | 34 | * |
21 | 35 | * @method |
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js |
— | — | @@ -249,6 +249,12 @@ |
250 | 250 | } |
251 | 251 | }; |
252 | 252 | |
| 253 | +es.ContentView.prototype.clearSelection = function() { |
| 254 | + this.$rangeStart.hide(); |
| 255 | + this.$rangeFill.hide(); |
| 256 | + this.$rangeEnd.hide(); |
| 257 | +}; |
| 258 | + |
253 | 259 | /** |
254 | 260 | * Gets the index of the rendered line a given offset is within. |
255 | 261 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js |
— | — | @@ -78,14 +78,22 @@ |
79 | 79 | * @param range {es.Range} Range of content to draw selection around |
80 | 80 | */ |
81 | 81 | 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 ) ); |
87 | 86 | } |
| 87 | + for ( var i = 0; i < views.off.length; i++ ) { |
| 88 | + views.off[i].clearSelection(); |
| 89 | + } |
88 | 90 | }; |
89 | 91 | |
| 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 | + |
90 | 98 | /** |
91 | 99 | * Gets length of contents. |
92 | 100 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js |
— | — | @@ -69,13 +69,13 @@ |
70 | 70 | * @param range {es.Range} Range of content to draw selection around |
71 | 71 | */ |
72 | 72 | 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 ) ); |
79 | 76 | } |
| 77 | + for ( var i = 0; i < views.off.length; i++ ) { |
| 78 | + views.off[i].clearSelection(); |
| 79 | + } |
80 | 80 | }; |
81 | 81 | |
82 | 82 | /** |
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js |
— | — | @@ -69,6 +69,10 @@ |
70 | 70 | this.contentView.drawSelection( range ); |
71 | 71 | }; |
72 | 72 | |
| 73 | +es.ParagraphBlockView.prototype.clearSelection = function( range ) { |
| 74 | + this.contentView.clearSelection(); |
| 75 | +}; |
| 76 | + |
73 | 77 | /** |
74 | 78 | * Gets length of contents. |
75 | 79 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js |
— | — | @@ -87,16 +87,22 @@ |
88 | 88 | * @param range {es.Range} Range of content to draw selection around |
89 | 89 | */ |
90 | 90 | 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 ) ); |
96 | 95 | } |
| 96 | + for ( var i = 0; i < views.off.length; i++ ) { |
| 97 | + views.off[i].clearSelection(); |
| 98 | + } |
97 | 99 | }; |
98 | 100 | |
| 101 | +es.TableBlockCellView.prototype.clearSelection = function( range ) { |
| 102 | + for ( var i = 0; i < this.items.length; i++ ) { |
| 103 | + this.items[i].clearSelection(); |
| 104 | + } |
| 105 | +}; |
99 | 106 | |
100 | | - |
101 | 107 | /** |
102 | 108 | * Gets HTML rendering of block. |
103 | 109 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js |
— | — | @@ -79,14 +79,22 @@ |
80 | 80 | * @param range {es.Range} Range of content to draw selection around |
81 | 81 | */ |
82 | 82 | 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 ) ); |
88 | 87 | } |
| 88 | + for ( var i = 0; i < views.off.length; i++ ) { |
| 89 | + views.off[i].clearSelection(); |
| 90 | + } |
89 | 91 | }; |
90 | 92 | |
| 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 | + |
91 | 99 | /** |
92 | 100 | * Gets length of contents. |
93 | 101 | * |