r93323 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93322‎ | r93323 | r93324 >
Date:22:30, 27 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Using es.Range everywhere
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Block.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlock.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlockItem.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ListBlockList.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Range.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.TextFlow.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.ListBlockItem.js
@@ -105,4 +105,4 @@
106106 };
107107
108108 es.extend( es.ListBlockItem, es.EventEmitter );
109 -es.extend( es.ListBlockItem, es.Container );
\ No newline at end of file
 109+es.extend( es.ListBlockItem, es.Container );
Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -265,23 +265,22 @@
266266 * TODO: Implement render option, which will allow annotations to influence output, such as an
267267 * image outputing it's URL
268268 *
 269+ * @param range {es.Range} Range of text to get
269270 * @param start {Integer} Optional beginning of range, if omitted range will begin at 0
270271 * @param end {Integer} Optional end of range, if omitted range will end a this.data.length
271272 * @param render {Boolean} If annotations should have any influence on output
272273 * @return {String} Plain text within given range
273274 */
274 -es.Content.prototype.getText = function( start, end, render ) {
275 - // Wrap values
276 - start = Math.max( 0, start || 0 );
277 - if ( end === undefined ) {
278 - end = this.data.length;
 275+es.Content.prototype.getText = function( range, render ) {
 276+ if ( !range ) {
 277+ range = new es.Range( 0, this.data.length );
279278 } else {
280 - end = Math.min( this.data.length, end );
 279+ range.normalize();
281280 }
282281 // Copy characters
283282 var text = '';
284283 var i;
285 - for ( i = start; i < end; i++ ) {
 284+ for ( i = range.start; i < range.end; i++ ) {
286285 // If not using in IE6 or IE7 (which do not support array access for strings) use this..
287286 // text += this.data[i][0];
288287 // Otherwise use this...
@@ -295,12 +294,16 @@
296295 *
297296 * Range arguments (start and end) are clamped if out of range.
298297 *
299 - * @param start {Integer} Optional beginning of range, if omitted range will begin at 0
300 - * @param end {Integer} Optional end of range, if omitted range will end a this.data.length
 298+ * @param range {es.Range} Range of content to get
301299 * @return {es.Content} New content object
302300 */
303 -es.Content.prototype.slice = function( start, end ) {
304 - return new es.Content( this.data.slice( start, end ) );
 301+es.Content.prototype.getContent = function( range ) {
 302+ if ( !range ) {
 303+ range = new es.Range( 0, this.data.length );
 304+ } else {
 305+ range.normalize();
 306+ }
 307+ return new es.Content( this.data.slice( range.start, range.end ) );
305308 };
306309
307310 /**
@@ -335,14 +338,13 @@
336339 /**
337340 * Removes content data within a specific range.
338341 *
339 - * @param start {Integer} Beginning of range
340 - * @param end {Integer} End of range
 342+ * @param range {Range} Range of content to remove
341343 */
342 -es.Content.prototype.remove = function( start, end ) {
343 - this.data.splice( start, end - start );
 344+es.Content.prototype.remove = function( range ) {
 345+ range.normalize();
 346+ this.data.splice( range.start, range.getLength() );
344347 this.emit( 'remove', {
345 - 'start': start,
346 - 'end': end
 348+ 'range': range
347349 } );
348350 this.emit( 'change', { 'type': 'remove' } );
349351 };
@@ -362,16 +364,15 @@
363365 * Strict coverage may be used to compare not only annotation types, but also their data. Since new
364366 * line characters are never annotated, they are always considered covered.
365367 *
366 - * @param start {Integer} Beginning of range
367 - * @param end {Integer} End of range
 368+ * @param range {es.Range} Range of content to analyze
368369 * @param annotation {Object} Annotation to compare with
369370 * @param strict {Boolean} Optionally compare annotation data as well as type
370371 * @return {Array} List of indexes of covered characters within content data
371372 */
372 -es.Content.prototype.coverageOfAnnotation = function( start, end, annotation, strict ) {
 373+es.Content.prototype.coverageOfAnnotation = function( range, annotation, strict ) {
373374 var coverage = [];
374375 var i, index;
375 - for ( i = start; i < end; i++ ) {
 376+ for ( i = range.start; i < range.end; i++ ) {
376377 index = this.indexOfAnnotation( i, annotation );
377378 if ( typeof this.data[i] !== 'string' && index !== -1 ) {
378379 if ( strict ) {
@@ -427,18 +428,19 @@
428429 *
429430 * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
430431 * @param annotation {Object} Annotation to apply
431 - * @param start {Integer} Offset to begin annotating from
432 - * @param end {Integer} Offset to stop annotating to
 432+ * @param range {es.Range} Range of content to annotate
433433 */
434 -es.Content.prototype.annotate = function( method, annotation, start, end ) {
 434+es.Content.prototype.annotate = function( method, annotation, range ) {
 435+ if ( !range ) {
 436+ range = new es.Range( 0, this.data.length );
 437+ } else {
 438+ range.normalize();
 439+ }
435440 var i;
436 -
437 - start = Math.max( start, 0 );
438 - end = Math.min( end, this.data.length );
439441 if ( method === 'toggle' ) {
440 - var coverage = this.coverageOfAnnotation( start, end, annotation, false );
441 - if ( coverage.length === end - start ) {
442 - var strictCoverage = this.coverageOfAnnotation( start, end, annotation, true );
 442+ var coverage = this.coverageOfAnnotation( range, annotation, false );
 443+ if ( coverage.length === range.getLength() ) {
 444+ var strictCoverage = this.coverageOfAnnotation( range, annotation, true );
443445 method = strictCoverage.length === coverage.length ? 'remove' : 'add';
444446 } else {
445447 method = 'add';
@@ -446,7 +448,7 @@
447449 }
448450 if ( method === 'add' ) {
449451 var duplicate;
450 - for ( i = start; i < end; i++ ) {
 452+ for ( i = range.start; i < range.end; i++ ) {
451453 duplicate = -1;
452454 if ( typeof this.data[i] === 'string' ) {
453455 // Never annotate new lines
@@ -468,7 +470,7 @@
469471 }
470472 }
471473 } else if ( method === 'remove' ) {
472 - for ( i = start; i < end; i++ ) {
 474+ for ( i = range.start; i < range.end; i++ ) {
473475 if ( typeof this.data[i] !== 'string' ) {
474476 if ( annotation.type === 'all' ) {
475477 // Remove all annotations by converting the annotated character to a plain
@@ -486,8 +488,7 @@
487489 this.emit( 'annotate', {
488490 'method': method,
489491 'annotation': annotation,
490 - 'start': start,
491 - 'end': end
 492+ 'range': range
492493 } );
493494 this.emit( 'change', { 'type': 'annotate' } );
494495 };
@@ -499,9 +500,9 @@
500501 * @param end {Integer} End of range
501502 * @param {String} Rendered HTML of content data
502503 */
503 -es.Content.prototype.render = function( start, end ) {
504 - if ( start || end ) {
505 - return this.slice( start, end ).render();
 504+es.Content.prototype.render = function( range ) {
 505+ if ( range ) {
 506+ return this.getContent( range ).render();
506507 }
507508 var out = '',
508509 left = '',
@@ -584,20 +585,16 @@
585586 line,
586587 offset = 0,
587588 i, j, k;
588 -
589589 for ( i = 0; i < this.data.length; i++ ) {
590 -
591590 if ( line == null ) {
592591 line = {
593592 text : '',
594593 annotations : []
595594 };
596595 }
597 -
598596 right = this.data[i];
599597 leftPlain = typeof left === 'string';
600598 rightPlain = typeof right === 'string';
601 -
602599 if ( rightPlain && right == "\n" ) {
603600 lines.push(line);
604601 line = null;
@@ -605,7 +602,6 @@
606603 left = '';
607604 continue;
608605 }
609 -
610606 if ( !leftPlain ) {
611607 for ( j = 1; j < left.length; j++ ) {
612608 for ( k = line.annotations.length - 1; k >= 0; k-- ) {
@@ -618,7 +614,6 @@
619615 }
620616 }
621617 }
622 -
623618 if ( !rightPlain ) {
624619 for ( j = 1; j < right.length; j++ ) {
625620 if ( leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) {
@@ -631,16 +626,12 @@
632627 }
633628 }
634629 }
635 -
636630 line.text += rightPlain ? right : right[0];
637 -
638631 left = right;
639632 }
640 -
641633 if ( line != null ) {
642634 lines.push(line);
643635 }
644 -
645636 return lines;
646637 };
647638
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js
@@ -90,10 +90,10 @@
9191 */
9292 var $ruler = $( '<div class="editSurface-ruler"></div>' ).appendTo( this.$ ),
9393 ruler = $ruler[0],
94 - fit = this.fitCharacters( line.start, line.end, ruler, position.left );
95 - ruler.innerHTML = this.content.render( line.start, fit.end );
 94+ fit = this.fitCharacters( line.range, ruler, position.left );
 95+ ruler.innerHTML = this.content.render( new es.Range( line.range.start, fit.end ) );
9696 var left = ruler.clientWidth;
97 - ruler.innerHTML = this.content.render( line.start, fit.end + 1 );
 97+ ruler.innerHTML = this.content.render( new es.Range( line.range.start, fit.end + 1 ) );
9898 var right = ruler.clientWidth;
9999 var center = Math.round( left + ( ( right - left ) / 2 ) );
100100 $ruler.remove();
@@ -103,7 +103,7 @@
104104 // If the position is right of the center of the character it's on top of, increment offset
105105 fit.end + ( position.left >= center ? 1 : 0 ),
106106 // If the line ends in a non-boundary character, decrement offset
107 - line.end + ( this.boundaryTest.exec( line.text.substr( -1 ) ) ? -1 : 0 )
 107+ line.range.end + ( this.boundaryTest.exec( line.text.substr( -1 ) ) ? -1 : 0 )
108108 );
109109 };
110110
@@ -147,7 +147,7 @@
148148 };
149149 while ( position.line < lineCount ) {
150150 line = this.lines[position.line];
151 - if ( offset >= line.start && offset < line.end ) {
 151+ if ( offset >= line.range.start && offset < line.range.end ) {
152152 position.bottom = position.top + line.height;
153153 break;
154154 }
@@ -174,10 +174,10 @@
175175 * Since the left position will be zero for the first character in the line, so we can skip
176176 * measuring for those cases.
177177 */
178 - if ( line.start < offset ) {
 178+ if ( line.range.start < offset ) {
179179 var $ruler = $( '<div class="editSurface-ruler"></div>' ).appendTo( this.$ ),
180180 ruler = $ruler[0];
181 - ruler.innerHTML = this.content.render( line.start, offset );
 181+ ruler.innerHTML = this.content.render( new es.Range( line.range.start, offset ) );
182182 position.left = ruler.clientWidth;
183183 $ruler.remove();
184184 }
@@ -240,7 +240,7 @@
241241 charFit = null,
242242 wordCount = this.boundaries.length;
243243 while ( ++iteration <= limit && rs.wordOffset < wordCount - 1 ) {
244 - wordFit = this.fitWords( rs.wordOffset, wordCount - 1, rs.ruler, rs.width );
 244+ wordFit = this.fitWords( new es.Range( rs.wordOffset, wordCount - 1 ), rs.ruler, rs.width );
245245 fractional = false;
246246 if ( wordFit.width > rs.width ) {
247247 // The first word didn't fit, we need to split it up
@@ -249,12 +249,16 @@
250250 rs.wordOffset++;
251251 lineEnd = this.boundaries[rs.wordOffset];
252252 do {
253 - charFit = this.fitCharacters( charOffset, lineEnd, rs.ruler, rs.width );
 253+ charFit = this.fitCharacters(
 254+ new es.Range( charOffset, lineEnd ), rs.ruler, rs.width
 255+ );
254256 // If we were able to get the rest of the characters on the line OK
255257 if ( charFit.end === lineEnd) {
256258 // Try to fit more words on the line
257259 wordFit = this.fitWords(
258 - rs.wordOffset, wordCount - 1, rs.ruler, rs.width - charFit.width
 260+ new es.Range( rs.wordOffset, wordCount - 1 ),
 261+ rs.ruler,
 262+ rs.width - charFit.width
259263 );
260264 if ( wordFit.end > rs.wordOffset ) {
261265 lineOffset = rs.wordOffset;
@@ -262,7 +266,7 @@
263267 charFit.end = lineEnd = this.boundaries[rs.wordOffset];
264268 }
265269 }
266 - this.appendLine( charOffset, charFit.end, lineOffset, fractional );
 270+ this.appendLine( new es.Range( charOffset, charFit.end ), lineOffset, fractional );
267271 // Move on to another line
268272 charOffset = charFit.end;
269273 // Mark the next line as fractional
@@ -270,7 +274,7 @@
271275 } while ( charOffset < lineEnd );
272276 } else {
273277 lineEnd = this.boundaries[wordFit.end];
274 - this.appendLine( lineStart, lineEnd, rs.wordOffset, fractional );
 278+ this.appendLine( new es.Range( lineStart, lineEnd ), rs.wordOffset, fractional );
275279 rs.wordOffset = wordFit.end;
276280 }
277281 lineStart = lineEnd;
@@ -344,10 +348,10 @@
345349 currentLine = this.lines.length - 1;
346350 for ( var i = this.lines.length - 1; i >= 0; i-- ) {
347351 var line = this.lines[i];
348 - if ( line.start < offset && line.end > offset ) {
 352+ if ( line.range.start < offset && line.range.end > offset ) {
349353 currentLine = i;
350354 }
351 - if ( ( line.end < offset && !line.fractional ) || i === 0 ) {
 355+ if ( ( line.range.end < offset && !line.fractional ) || i === 0 ) {
352356 rs.lines = this.lines.slice( 0, i );
353357 rs.wordOffset = line.wordOffset;
354358 gap = currentLine - i;
@@ -365,12 +369,13 @@
366370 /**
367371 * Adds a line containing a given range of text to the end of the DOM and the "lines" array.
368372 *
 373+ * @param range {es.Range} Range of content to append
369374 * @param start {Integer} Beginning of text range for line
370375 * @param end {Integer} Ending of text range for line
371376 * @param wordOffset {Integer} Index within this.words which the line begins with
372377 * @param fractional {Boolean} If the line begins in the middle of a word
373378 */
374 -es.TextFlow.prototype.appendLine = function( start, end, wordOffset, fractional ) {
 379+es.TextFlow.prototype.appendLine = function( range, wordOffset, fractional ) {
375380 var rs = this.renderState,
376381 lineCount = rs.lines.length;
377382 $line = this.$.find( '.editSurface-line[line-index=' + lineCount + ']' );
@@ -378,12 +383,11 @@
379384 $line = $( '<div class="editSurface-line" line-index="' + lineCount + '"></div>' )
380385 .appendTo( this.$ );
381386 }
382 - $line[0].innerHTML = this.content.render( start, end );
 387+ $line[0].innerHTML = this.content.render( range );
383388 // Collect line information
384389 rs.lines.push({
385 - 'text': this.content.getText( start, end ),
386 - 'start': start,
387 - 'end': end,
 390+ 'text': this.content.getText( range ),
 391+ 'range': range,
388392 'width': $line.outerWidth(),
389393 'height': $line.outerHeight(),
390394 'wordOffset': wordOffset,
@@ -415,14 +419,15 @@
416420 * starting with [offset .. limit], which usually results in reducing the end position in all but
417421 * the last line, and in most cases more than 3 times, before changing directions.
418422 *
419 - * @param start {Integer} Index within "words" to begin fitting from
420 - * @param end {Integer} Index within "words" to stop fitting to
 423+ * @param range {es.Range} Range of content to try to fit
421424 * @param ruler {HTMLElement} Element to take measurements with
422425 * @param width {Integer} Maximum width to allow the line to extend to
423426 * @return {Integer} Last index within "words" that contains a word that fits
424427 */
425 -es.TextFlow.prototype.fitWords = function( start, end, ruler, width ) {
426 - var offset = start,
 428+es.TextFlow.prototype.fitWords = function( range, ruler, width ) {
 429+ var offset = range.start,
 430+ start = range.start,
 431+ end = range.end,
427432 charOffset = this.boundaries[offset],
428433 middle,
429434 lineWidth,
@@ -435,7 +440,7 @@
436441 // Measure and cache width of substring
437442 cacheKey = charOffset + ':' + charMiddle;
438443 // Prepare the line for measurement using pre-escaped HTML
439 - ruler.innerHTML = this.content.render( charOffset, charMiddle );
 444+ ruler.innerHTML = this.content.render( new es.Range( charOffset, charMiddle ) );
440445 // Test for over/under using width of the rendered line
441446 this.widthCache[cacheKey] = lineWidth = ruler.clientWidth;
442447
@@ -457,7 +462,7 @@
458463 if ( end === middle - 1 ) {
459464 // A final measurement is required
460465 var charStart = this.boundaries[start];
461 - ruler.innerHTML = this.content.render( charOffset, charStart );
 466+ ruler.innerHTML = this.content.render( new es.Range( charOffset, charStart ) );
462467 lineWidth = this.widthCache[charOffset + ':' + charStart] = ruler.clientWidth;
463468 }
464469 return { 'end': start, 'width': lineWidth };
@@ -470,14 +475,15 @@
471476 * used to detect when the first character was too long to fit on a line. In such cases the result
472477 * will contain the index of the first character and it's width.
473478 *
474 - * @param start {Integer} Index within "text" to begin fitting from
475 - * @param end {Integer} Index within "text" to stop fitting to
 479+ * @param range {es.Range} Range of content to try to fit
476480 * @param ruler {HTMLElement} Element to take measurements with
477481 * @param width {Integer} Maximum width to allow the line to extend to
478482 * @return {Integer} Last index within "text" that contains a character that fits
479483 */
480 -es.TextFlow.prototype.fitCharacters = function( start, end, ruler, width ) {
481 - var offset = start,
 484+es.TextFlow.prototype.fitCharacters = function( range, ruler, width ) {
 485+ var offset = range.start,
 486+ start = range.start,
 487+ end = range.end,
482488 middle,
483489 lineWidth,
484490 cacheKey;
@@ -491,7 +497,7 @@
492498 lineWidth = this.widthCache[cacheKey];
493499 } else {
494500 // Fill the line with a portion of the text, escaped as HTML
495 - ruler.innerHTML = this.content.render( offset, middle );
 501+ ruler.innerHTML = this.content.render( new es.Range( offset, middle ) );
496502 // Test for over/under using width of the rendered line
497503 this.widthCache[cacheKey] = lineWidth = ruler.clientWidth;
498504 }
@@ -517,7 +523,7 @@
518524 lineWidth = this.widthCache[cacheKey];
519525 } else {
520526 // A final measurement is required
521 - ruler.innerHTML = this.content.render( offset, start );
 527+ ruler.innerHTML = this.content.render( new es.Range( offset, start ) );
522528 lineWidth = this.widthCache[cacheKey] = ruler.clientWidth;
523529 }
524530 }
Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js
@@ -46,17 +46,10 @@
4747 /**
4848 * Deletes content in a block within a range.
4949 *
50 - * @param start {Integer} Offset to start removing content from
51 - * @param end {Integer} Offset to start removing content to
 50+ * @param range {es.Range} Range of content to remove
5251 */
53 -es.ParagraphBlock.prototype.deleteContent = function( start, end ) {
54 - // Normalize start/end
55 - if ( end < start ) {
56 - var tmp = end;
57 - end = start;
58 - start = tmp;
59 - }
60 - this.content.remove( start, end );
 52+es.ParagraphBlock.prototype.deleteContent = function( range ) {
 53+ this.content.remove( range );
6154 };
6255
6356 /**
@@ -66,11 +59,10 @@
6760 *
6861 * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
6962 * @param annotation {Object} Annotation to apply
70 - * @param start {Integer} Offset to begin annotating from
71 - * @param end {Integer} Offset to stop annotating to
 63+ * @param range {es.Range} Range of content to annotate
7264 */
73 -es.ParagraphBlock.prototype.annotateContent = function( method, annotation, start, end ) {
74 - this.content.annotate( method, annotation, start, end );
 65+es.ParagraphBlock.prototype.annotateContent = function( method, annotation, range ) {
 66+ this.content.annotate( method, annotation, range );
7567 };
7668
7769 /**
@@ -79,19 +71,18 @@
8072 * @param start {Integer} Offset to get content from
8173 * @param end {Integer} Offset to get content to
8274 */
83 -es.Block.prototype.getContent = function( start, end ) {
84 - return this.content.slice( start, end );
 75+es.Block.prototype.getContent = function( range ) {
 76+ return this.content.getContent( range );
8577 };
8678
8779 /**
8880 * Gets content as plain text within a range.
8981 *
90 - * @param start {Integer} Offset to start get text from
91 - * @param end {Integer} Offset to start get text to
 82+ * @param range {es.Range} Range of text to get
9283 * @param render {Boolean} If annotations should have any influence on output
9384 */
94 -es.Block.prototype.getText = function( start, end, render ) {
95 - return this.content.getText( start, end, render );
 85+es.Block.prototype.getText = function( range, render ) {
 86+ return this.content.getText( range, render );
9687 };
9788
9889 /**
@@ -146,6 +137,6 @@
147138 /**
148139 * Extend es.Block to support paragraph block creation with es.Block.newFromWikidom
149140 */
150 -es.Block.models.paragraph = es.ParagraphBlock;
 141+es.Block.models.paragraph = es.ParagraphBlock;
151142
152143 es.extend( es.ParagraphBlock, es.Block );
Index: trunk/parsers/wikidom/lib/es/es.ListBlockList.js
@@ -73,4 +73,4 @@
7474 };
7575
7676 es.extend( es.ListBlockList, es.EventEmitter );
77 -es.extend( es.ListBlockList, es.Container );
\ No newline at end of file
 77+es.extend( es.ListBlockList, es.Container );
Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js
@@ -49,18 +49,14 @@
5050 /**
5151 * Deletes content in a block within a range.
5252 *
53 - * @param offset {Integer} Offset to start removing content from
54 - * @param length {Integer} Offset to start removing content to
 53+ * @param range {es.Range} Range of content to remove
5554 */
56 -es.ListBlock.prototype.deleteContent = function( start, end ) {
57 - // Normalize start/end
58 - if ( end < start ) {
59 - var tmp = end;
60 - end = start;
61 - start = tmp;
62 - }
63 - var location = this.list.getLocationFromOffset( start );
64 - location.item.flow.content.remove( location.offset, location.offset + end - start );
 55+es.ListBlock.prototype.deleteContent = function( range ) {
 56+ range.normalize();
 57+ var location = this.list.getLocationFromOffset( range.start );
 58+ location.item.flow.content.remove(
 59+ new es.Range( location.offset, location.offset + range.getLength() )
 60+ );
6561 };
6662
6763 /**
@@ -70,22 +66,23 @@
7167 *
7268 * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
7369 * @param annotation {Object} Annotation to apply
74 - * @param start {Integer} Offset to begin annotating from
75 - * @param end {Integer} Offset to stop annotating to
 70+ * @param range {es.Range} Range of content to annotate
7671 */
77 -es.ListBlock.prototype.annotateContent = function( method, annotation, start, end ) {
 72+es.ListBlock.prototype.annotateContent = function( method, annotation, range ) {
 73+ range.normalize();
7874 // TODO: Support annotating multiple items at once
79 - var location = this.list.getLocationFromOffset( start );
80 - location.item.content.annotate( method, annotation, location.offset, location.offset + end - start );
 75+ var location = this.list.getLocationFromOffset( range.start );
 76+ location.item.content.annotate(
 77+ method, annotation, new es.Range( location.offset, location.offset + range.getLength() )
 78+ );
8179 };
8280
8381 /**
8482 * Gets content within a range.
8583 *
86 - * @param start {Integer} Offset to get content from
87 - * @param end {Integer} Offset to get content to
 84+ * @param range {es.Range} Range of content to get
8885 */
89 -es.ListBlock.prototype.getContent = function() {
 86+es.ListBlock.prototype.getContent = function( range ) {
9087 // TODO: Implement me!
9188 return new Content();
9289 };
@@ -93,11 +90,10 @@
9491 /**
9592 * Gets content as plain text within a range.
9693 *
97 - * @param start {Integer} Offset to start get text from
98 - * @param end {Integer} Offset to start get text to
 94+ * @param range {Range} Range of text to get
9995 * @param render {Boolean} If annotations should have any influence on output
10096 */
101 -es.ListBlock.prototype.getText = function() {
 97+es.ListBlock.prototype.getText = function( range ) {
10298 // TODO: Implement me!
10399 return '';
104100 };
Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -18,7 +18,7 @@
1919 'clickDelay': 500,
2020 'clickTimeout': null,
2121 'clickPosition': null,
22 - 'hotSpotRadius': 2
 22+ 'hotSpotRadius': 1
2323 };
2424 this.keyboard = {
2525 'selecting': false,
@@ -452,7 +452,9 @@
453453 this.$rangeFill.hide();
454454 }
455455 }
456 - text += from.location.block.getText( from.location.offset, to.location.offset );
 456+ text += from.location.block.getText(
 457+ new es.Range( from.location.offset, to.location.offset )
 458+ );
457459 } else {
458460 // Multiple block selection
459461 blockWidth = Math.max(
@@ -499,7 +501,7 @@
500502 };
501503
502504 /**
503 - * Sets the selection to a new range.
 505+ * Sets the selection to a new es.Range.
504506 *
505507 * @param from {es.Selection} Selection to apply
506508 */
@@ -653,7 +655,7 @@
654656 to = selection.end;
655657 if ( from.block === to.block ) {
656658 // Single block deletion
657 - from.block.deleteContent( from.offset, to.offset );
 659+ from.block.deleteContent( new es.Range( from.offset, to.offset ) );
658660 } else {
659661 // Multiple block deletion
660662 var block;
@@ -661,13 +663,13 @@
662664 block = this.doc.blocks[i];
663665 if ( block === from.block ) {
664666 // From offset to length
665 - block.deleteContent( from.offset, block.getLength() );
 667+ block.deleteContent( new es.Range( from.offset, block.getLength() ) );
666668 } else if ( block === to.block ) {
667669 // From 0 to offset
668 - block.deleteContent( 0, to.offset );
 670+ block.deleteContent( new es.Range( 0, to.offset ) );
669671 } else {
670672 // Full coverage
671 - block.deleteContent( 0, block.getLength() );
 673+ block.deleteContent( new es.Range( 0, block.getLength() ) );
672674 }
673675 }
674676 }
@@ -696,7 +698,7 @@
697699 to = selection.end;
698700 if ( from.block === to.block ) {
699701 // Single block annotation
700 - from.block.annotateContent( method, annotation, from.offset, to.offset );
 702+ from.block.annotateContent( method, annotation, new es.Range( from.offset, to.offset ) );
701703 } else {
702704 // Multiple block annotation
703705 var block;
@@ -704,13 +706,15 @@
705707 block = this.doc.blocks[i];
706708 if ( block === from.block ) {
707709 // From offset to length
708 - block.annotateContent( method, annotation, from.offset, block.getLength() );
 710+ block.annotateContent(
 711+ method, annotation, new es.Range( from.offset, block.getLength() )
 712+ );
709713 } else if ( block === to.block ) {
710714 // From 0 to offset
711 - block.annotateContent( method, annotation, 0, to.offset );
 715+ block.annotateContent( method, annotation, new es.Range( 0, to.offset ) );
712716 } else {
713717 // Full coverage
714 - block.annotateContent( method, annotation, 0, block.getLength() );
 718+ block.annotateContent( method, annotation, new es.Range( 0, block.getLength() ) );
715719 }
716720 }
717721 }
Index: trunk/parsers/wikidom/lib/es/es.Block.js
@@ -88,10 +88,9 @@
8989 /**
9090 * Deletes content in a block within a range.
9191 *
92 - * @param offset {Integer} Offset to start removing content from
93 - * @param length {Integer} Offset to start removing content to
 92+ * @param range {es.Range} Range of content to remove
9493 */
95 -es.Block.prototype.deleteContent = function( start, end ) {
 94+es.Block.prototype.deleteContent = function( range ) {
9695 throw 'Block.deleteContent not implemented in this subclass.';
9796 };
9897
@@ -102,31 +101,28 @@
103102 *
104103 * @param method {String} Way to apply annotation ("toggle", "add" or "remove")
105104 * @param annotation {Object} Annotation to apply
106 - * @param start {Integer} Offset to begin annotating from
107 - * @param end {Integer} Offset to stop annotating to
 105+ * @param range {es.Range} Range of content to annotate
108106 */
109 -es.Block.prototype.annotateContent = function( method, annotation, start, end ) {
 107+es.Block.prototype.annotateContent = function( method, annotation, range ) {
110108 throw 'Block.annotateContent not implemented in this subclass.';
111109 };
112110
113111 /**
114112 * Gets content within a range.
115113 *
116 - * @param start {Integer} Offset to get content from
117 - * @param end {Integer} Offset to get content to
 114+ * @param range {es.Range} Range of content to get
118115 */
119 -es.Block.prototype.getContent = function( start, end ) {
 116+es.Block.prototype.getContent = function( range) {
120117 throw 'Block.getContent not implemented in this subclass.';
121118 };
122119
123120 /**
124121 * Gets content as plain text within a range.
125122 *
126 - * @param start {Integer} Offset to start get text from
127 - * @param end {Integer} Offset to start get text to
 123+ * @param range {es.Range} Range of text to get
128124 * @param render {Boolean} If annotations should have any influence on output
129125 */
130 -es.Block.prototype.getText = function( start, end, render ) {
 126+es.Block.prototype.getText = function( range, render ) {
131127 throw 'Block.getText not implemented in this subclass.';
132128 };
133129
Index: trunk/parsers/wikidom/lib/es/es.Range.js
@@ -10,14 +10,10 @@
1111 * @property end {Integer}
1212 */
1313 es.Range = function( from, to ) {
14 - this.set( from, to );
15 -};
16 -
17 -es.Range.prototype.set = function( from, to ) {
1814 this.from = from || 0;
1915 this.to = to || from;
2016 this.normalize();
21 -}
 17+};
2218
2319 es.Range.prototype.getLength = function() {
2420 return Math.abs( this.from - this.to );

Status & tagging log