Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js |
— | — | @@ -62,16 +62,27 @@ |
63 | 63 | while ( line < lineCount ) { |
64 | 64 | bottom += lines[line].height; |
65 | 65 | if ( position.y >= top && position.y < bottom ) { |
66 | | - offset = lines[line].start; |
67 | 66 | break; |
68 | 67 | } |
69 | 68 | top = bottom; |
70 | 69 | line++; |
71 | 70 | }; |
72 | 71 | |
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(); |
74 | 85 | |
75 | | - return offset; |
| 86 | + return fit.end; |
76 | 87 | }; |
77 | 88 | |
78 | 89 | /** |
— | — | @@ -213,9 +224,8 @@ |
214 | 225 | * inconsistencies between browsers and box models, we can just create an element inside the |
215 | 226 | * container and measure it. |
216 | 227 | */ |
217 | | - var $ruler = $( '<div> </div>' ).appendTo( this.$ ); |
218 | | - var width = $ruler.innerWidth() |
219 | | - $ruler.remove(); |
| 228 | + var $ruler = $( '<div> </div>' ).appendTo( this.$ ), |
| 229 | + width = $ruler.innerWidth() |
220 | 230 | |
221 | 231 | // Ignore offset optimization if the width has changed or the text has never been flowed before |
222 | 232 | if (this.width !== width) { |
— | — | @@ -234,8 +244,7 @@ |
235 | 245 | wordFit, |
236 | 246 | charOffset, |
237 | 247 | charFit, |
238 | | - $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( this.$ ), |
239 | | - ruler = $ruler[0]; |
| 248 | + ruler = $ruler.addClass('editSurface-line')[0]; |
240 | 249 | while ( wordOffset < this.boundaries.length ) { |
241 | 250 | wordFit = this.fitWords( wordOffset, this.words.length, ruler, width ); |
242 | 251 | if ( wordFit.width > width ) { |