@@ -463,22 +463,30 @@ function sizeAndStyleRect(cellRect) {
463
463
function populateCellText ( cellText , tableControlView , allColumnBlock , gd ) {
464
464
cellText
465
465
. text ( function ( d ) {
466
+
466
467
var col = d . column . specIndex ;
467
468
var row = d . rowNumber ;
469
+
468
470
var userSuppliedContent = d . value ;
471
+ var stringSupplied = ( typeof userSuppliedContent === 'string' ) ;
472
+ var hasBreaks = stringSupplied && userSuppliedContent . match ( / < b r > / i) ;
473
+ var userBrokenText = ! stringSupplied || hasBreaks ;
474
+ d . mayHaveMarkup = stringSupplied && userSuppliedContent . match ( / [ < & > ] / ) ;
475
+
469
476
var latex = isLatex ( userSuppliedContent ) ;
470
- var userBrokenText = ( typeof userSuppliedContent !== 'string' ) || userSuppliedContent . match ( / < b r > / i ) ;
471
- var userBrokenText2 = ( typeof userSuppliedContent === 'string' ) && userSuppliedContent . match ( / < b r > / i ) ;
477
+ d . latex = latex ;
478
+
472
479
var prefix = latex ? '' : gridPick ( d . calcdata . cells . prefix , col , row ) || '' ;
473
480
var suffix = latex ? '' : gridPick ( d . calcdata . cells . suffix , col , row ) || '' ;
474
481
var format = latex ? null : gridPick ( d . calcdata . cells . format , col , row ) || null ;
482
+
475
483
var prefixSuffixedText = prefix + ( format ? d3 . format ( format ) ( d . value ) : d . value ) + suffix ;
476
- d . latex = latex ;
477
- d . mayHaveMarkup = ( typeof userSuppliedContent === 'string' ) && userSuppliedContent . match ( / [ < & > ] / ) ;
484
+
478
485
var hasWrapSplitCharacter ;
479
- var hwsc = function ( prefixSuffixedText ) { return prefixSuffixedText . indexOf ( c . wrapSplitCharacter ) !== - 1 ; } ;
480
- d . wrappingNeeded = ! d . wrapped && ! userBrokenText && ! latex && ( hasWrapSplitCharacter = hwsc ( prefixSuffixedText ) ) ;
481
- d . cellHeightMayIncrease = userBrokenText2 || latex || d . mayHaveMarkup || ( hasWrapSplitCharacter === void ( 0 ) ? hwsc ( prefixSuffixedText ) : hasWrapSplitCharacter ) ;
486
+ d . wrappingNeeded = ! d . wrapped && ! userBrokenText && ! latex && ( hasWrapSplitCharacter = hasWrapCharacter ( prefixSuffixedText ) ) ;
487
+ d . cellHeightMayIncrease = hasBreaks || latex || d . mayHaveMarkup || ( hasWrapSplitCharacter === void ( 0 ) ? hasWrapCharacter ( prefixSuffixedText ) : hasWrapSplitCharacter ) ;
488
+ d . needsConvertToTspans = d . mayHaveMarkup || d . wrappingNeeded || d . latex ;
489
+
482
490
var textToRender ;
483
491
if ( d . wrappingNeeded ) {
484
492
var hrefPreservedText = c . wrapSplitCharacter === ' ' ? prefixSuffixedText . replace ( / < a h r e f = / ig, '<a_href=' ) : prefixSuffixedText ;
@@ -494,7 +502,7 @@ function populateCellText(cellText, tableControlView, allColumnBlock, gd) {
494
502
return textToRender ;
495
503
} )
496
504
. attr ( 'alignment-baseline' , function ( d ) {
497
- return d . cellHeightMayIncrease ? null : 'hanging' ;
505
+ return d . needsConvertToTspans ? null : 'hanging' ;
498
506
} )
499
507
. each ( function ( d ) {
500
508
@@ -504,7 +512,7 @@ function populateCellText(cellText, tableControlView, allColumnBlock, gd) {
504
512
// finalize what's in the DOM
505
513
506
514
var renderCallback = d . wrappingNeeded ? wrapTextMaker : updateYPositionMaker ;
507
- if ( d . mayHaveMarkup || d . wrappingNeeded || d . latex ) {
515
+ if ( d . needsConvertToTspans ) {
508
516
svgUtil . convertToTspans ( selection , gd , renderCallback ( allColumnBlock , element , tableControlView , gd , d ) ) ;
509
517
} else {
510
518
d3 . select ( element . parentNode )
@@ -525,6 +533,8 @@ function isLatex(content) {
525
533
return typeof content === 'string' && content . match ( c . latexCheck ) ;
526
534
}
527
535
536
+ function hasWrapCharacter ( text ) { return text . indexOf ( c . wrapSplitCharacter ) !== - 1 ; }
537
+
528
538
function columnMoved ( gd , calcdata , i , indices ) {
529
539
var o = calcdata [ i ] [ 0 ] . gdColumnsOriginalOrder ;
530
540
calcdata [ i ] [ 0 ] . gdColumns . sort ( function ( a , b ) {
@@ -609,7 +619,7 @@ function splitToCells(d) {
609
619
// But it has to be busted when `svgUtil.convertToTspans` is used as it reshapes cell subtrees asynchronously,
610
620
// and by that time the user may have scrolled away, resulting in stale overwrites. The real solution will be
611
621
// to turn `svgUtil.convertToTspans` into a cancelable request, in which case no key busting is needed.
612
- var buster = ( typeof v === 'string' ) && v . match ( / [ < $ & > ] / ) ? '_keybuster_' + Math . random ( ) : '' ;
622
+ var buster = ( typeof v === 'string' ) && v . match ( / [ < $ & > ] / ) ? '_keybuster_' + Math . random ( ) : '' ;
613
623
return {
614
624
// keyWithinBlock: /*fromTo[0] + */i, // optimized future version - no busting
615
625
// keyWithinBlock: fromTo[0] + i, // initial always-unoptimized version - janky scrolling with 5+ columns
0 commit comments