Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js |
— | — | @@ -224,14 +224,14 @@ |
225 | 225 | rs.charFit.end = rs.lineEnd = this.boundaries[rs.wordOffset]; |
226 | 226 | } |
227 | 227 | } |
228 | | - this.appendLine( rs.charOffset, rs.charFit.end ); |
| 228 | + this.appendLine( rs.charOffset, rs.charFit.end, rs.wordOffset, true ); |
229 | 229 | // Move on to another line |
230 | 230 | rs.charOffset = rs.charFit.end; |
231 | 231 | } while ( rs.charOffset < rs.lineEnd ); |
232 | 232 | } else { |
233 | 233 | rs.wordOffset = rs.wordFit.end; |
234 | 234 | rs.lineEnd = this.boundaries[rs.wordOffset]; |
235 | | - this.appendLine( rs.lineStart, rs.lineEnd ); |
| 235 | + this.appendLine( rs.lineStart, rs.lineEnd, rs.wordOffset, false ); |
236 | 236 | } |
237 | 237 | rs.lineStart = rs.lineEnd; |
238 | 238 | } |
— | — | @@ -317,7 +317,7 @@ |
318 | 318 | * @param start {Integer} Beginning of text range for line |
319 | 319 | * @param end {Integer} Ending of text range for line |
320 | 320 | */ |
321 | | -TextFlow.prototype.appendLine = function( start, end ) { |
| 321 | +TextFlow.prototype.appendLine = function( start, end, word, fractional ) { |
322 | 322 | $line = this.$.find( '.editSurface-line[line-index=' + this.lines.length + ']' ); |
323 | 323 | if ( !$line.length ) { |
324 | 324 | $line = $( '<div class="editSurface-line" line-index="' + this.lines.length + '"></div>' ) |
— | — | @@ -330,8 +330,11 @@ |
331 | 331 | 'start': start, |
332 | 332 | 'end': end, |
333 | 333 | 'width': $line.outerWidth(), |
334 | | - 'height': $line.outerHeight() |
| 334 | + 'height': $line.outerHeight(), |
| 335 | + 'word': word, |
| 336 | + 'fractional': fractional |
335 | 337 | }); |
| 338 | + //console.log( start, end, this.lines[this.lines.length - 1].text, this.lines[this.lines.length - 1].fractional ); |
336 | 339 | }; |
337 | 340 | |
338 | 341 | /** |
— | — | @@ -358,20 +361,22 @@ |
359 | 362 | */ |
360 | 363 | TextFlow.prototype.fitWords = function( start, end, ruler, width ) { |
361 | 364 | var offset = start, |
| 365 | + charOffset = this.boundaries[offset], |
362 | 366 | middle, |
363 | 367 | lineWidth, |
364 | 368 | cacheKey; |
365 | 369 | do { |
366 | 370 | // Place "middle" directly in the center of "start" and "end" |
367 | 371 | middle = Math.ceil( ( start + end ) / 2 ); |
| 372 | + charMiddle = this.boundaries[middle]; |
368 | 373 | |
369 | | - cacheKey = this.boundaries[offset] + ':' + this.boundaries[middle]; |
370 | | - |
| 374 | + // Measure and cache width of substring |
| 375 | + cacheKey = charOffset + ':' + charMiddle; |
371 | 376 | // Prepare the line for measurement using pre-escaped HTML |
372 | | - ruler.innerHTML = this.content.render( this.boundaries[offset], this.boundaries[middle] ); |
| 377 | + ruler.innerHTML = this.content.render( charOffset, charMiddle ); |
373 | 378 | // Test for over/under using width of the rendered line |
374 | 379 | this.widthCache[cacheKey] = lineWidth = ruler.clientWidth; |
375 | | - |
| 380 | + |
376 | 381 | // Test for over/under using width of the rendered line |
377 | 382 | if ( lineWidth > width ) { |
378 | 383 | // Detect impossible fit (the first word won't fit by itself) |
— | — | @@ -386,6 +391,13 @@ |
387 | 392 | start = middle; |
388 | 393 | } |
389 | 394 | } while ( start < end ); |
| 395 | + // Check if we ended by moving end to the left of middle |
| 396 | + if ( end === middle - 1 ) { |
| 397 | + // A final measurement is required |
| 398 | + var charStart = this.boundaries[start]; |
| 399 | + ruler.innerHTML = this.content.render( charOffset, charStart ); |
| 400 | + lineWidth = this.widthCache[charOffset + ':' + charStart] = ruler.clientWidth; |
| 401 | + } |
390 | 402 | return { 'end': start, 'width': lineWidth }; |
391 | 403 | }; |
392 | 404 | |
— | — | @@ -411,8 +423,8 @@ |
412 | 424 | // Place "middle" directly in the center of "start" and "end" |
413 | 425 | middle = Math.ceil( ( start + end ) / 2 ); |
414 | 426 | |
| 427 | + // Measure and cache width of substring |
415 | 428 | cacheKey = offset + ':' + middle; |
416 | | - |
417 | 429 | if ( cacheKey in this.widthCache ) { |
418 | 430 | lineWidth = this.widthCache[cacheKey]; |
419 | 431 | } else { |
— | — | @@ -421,7 +433,7 @@ |
422 | 434 | // Test for over/under using width of the rendered line |
423 | 435 | this.widthCache[cacheKey] = lineWidth = ruler.clientWidth; |
424 | 436 | } |
425 | | - |
| 437 | + |
426 | 438 | if ( lineWidth > width ) { |
427 | 439 | // Detect impossible fit (the first character won't fit by itself) |
428 | 440 | if (middle - offset === 1) { |
— | — | @@ -435,6 +447,18 @@ |
436 | 448 | start = middle; |
437 | 449 | } |
438 | 450 | } while ( start < end ); |
| 451 | + // Check if we ended by moving end to the left of middle |
| 452 | + if ( end === middle - 1 ) { |
| 453 | + // Try for cache hit |
| 454 | + cacheKey = offset + ':' + start; |
| 455 | + if ( cacheKey in this.widthCache ) { |
| 456 | + lineWidth = this.widthCache[cacheKey]; |
| 457 | + } else { |
| 458 | + // A final measurement is required |
| 459 | + ruler.innerHTML = this.content.render( offset, start ); |
| 460 | + lineWidth = this.widthCache[cacheKey] = ruler.clientWidth; |
| 461 | + } |
| 462 | + } |
439 | 463 | return { 'end': start, 'width': lineWidth }; |
440 | 464 | }; |
441 | 465 | |