r91295 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91294‎ | r91295 | r91296 >
Date:21:09, 1 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Initial implementation of horizontal finding for TextFlow.getOffset
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.TextFlow.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js
@@ -62,16 +62,27 @@
6363 while ( line < lineCount ) {
6464 bottom += lines[line].height;
6565 if ( position.y >= top && position.y < bottom ) {
66 - offset = lines[line].start;
6766 break;
6867 }
6968 top = bottom;
7069 line++;
7170 };
7271
73 - // TODO: Find horizontal offset from position
 72+ /*
 73+ * Offset finding
 74+ *
 75+ * Now that we know which line we are on, we can just use the "fitCharacters" method to get the
 76+ * last offset before "position.x".
 77+ *
 78+ * TODO: The offset needs to be chosen based on nearest offset to the cursor, not offset before
 79+ * the cursor.
 80+ */
 81+ var $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( this.$ )
 82+ ruler = $ruler[0],
 83+ fit = this.fitCharacters( lines[line].start, lines[line].end, ruler, position.x );
 84+ $ruler.remove();
7485
75 - return offset;
 86+ return fit.end;
7687 };
7788
7889 /**
@@ -213,9 +224,8 @@
214225 * inconsistencies between browsers and box models, we can just create an element inside the
215226 * container and measure it.
216227 */
217 - var $ruler = $( '<div>&nbsp;</div>' ).appendTo( this.$ );
218 - var width = $ruler.innerWidth()
219 - $ruler.remove();
 228+ var $ruler = $( '<div>&nbsp;</div>' ).appendTo( this.$ ),
 229+ width = $ruler.innerWidth()
220230
221231 // Ignore offset optimization if the width has changed or the text has never been flowed before
222232 if (this.width !== width) {
@@ -234,8 +244,7 @@
235245 wordFit,
236246 charOffset,
237247 charFit,
238 - $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( this.$ ),
239 - ruler = $ruler[0];
 248+ ruler = $ruler.addClass('editSurface-line')[0];
240249 while ( wordOffset < this.boundaries.length ) {
241250 wordFit = this.fitWords( wordOffset, this.words.length, ruler, width );
242251 if ( wordFit.width > width ) {

Status & tagging log