@@ -95,6 +95,16 @@ class DiffTextWindowData
95
95
Diff3WrapLineVector m_diff3WrapLineVector;
96
96
const ManualDiffHelpList* m_pManualDiffHelpList;
97
97
98
+ class WrapLineCacheData
99
+ {
100
+ public:
101
+ WrapLineCacheData () : m_d3LineIdx(0 ), m_textStart(0 ), m_textLength(0 ) {}
102
+ WrapLineCacheData ( int d3LineIdx, int textStart, int textLength )
103
+ : m_d3LineIdx(d3LineIdx), m_textStart(textStart), m_textLength(textLength) {}
104
+ int m_d3LineIdx; int m_textStart; int m_textLength;
105
+ };
106
+ QVector<WrapLineCacheData> m_wrapLineCache;
107
+
98
108
Options* m_pOptions;
99
109
QColor m_cThis;
100
110
QColor m_cDiff1;
@@ -835,8 +845,8 @@ void DiffTextWindowData::prepareTextLayout( QTextLayout& textLayout, bool bFirst
835
845
break ;
836
846
837
847
height += leading;
838
- if ( !bFirstLine )
839
- indentation = m_pDiffTextWindow->fontMetrics ().width (' ' ) * m_pOptions->m_tabSize ;
848
+ // if ( !bFirstLine )
849
+ // indentation = m_pDiffTextWindow->fontMetrics().width(' ') * m_pOptions->m_tabSize;
840
850
if ( visibleTextWidth>=0 )
841
851
{
842
852
line.setLineWidth ( visibleTextWidth -indentation );
@@ -997,7 +1007,7 @@ void DiffTextWindowData::writeLine(
997
1007
++outPos;
998
1008
} // end for
999
1009
1000
- QTextLayout textLayout ( lineString.mid ( wrapLineOffset, lineLength), m_pDiffTextWindow->font (), m_pDiffTextWindow );
1010
+ QTextLayout textLayout ( lineString.mid ( wrapLineOffset, lineLength-wrapLineOffset ), m_pDiffTextWindow->font (), m_pDiffTextWindow );
1001
1011
prepareTextLayout ( textLayout, !m_bWordWrap || wrapLineOffset==0 );
1002
1012
textLayout.draw ( &p, QPoint (0 , yOffset), frh.m_formatRanges /* , const QRectF & clip = QRectF() */ );
1003
1013
}
@@ -1527,6 +1537,9 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
1527
1537
1528
1538
d->m_bWordWrap = bWordWrap;
1529
1539
1540
+ if ( !bWordWrap || wrapLineVectorSize==0 )
1541
+ d->m_wrapLineCache .clear ();
1542
+
1530
1543
if ( bWordWrap )
1531
1544
{
1532
1545
ProgressProxy pp;
@@ -1540,27 +1553,45 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
1540
1553
visibleTextWidth-= d->leftInfoWidth () * fontMetrics ().width (' 0' );
1541
1554
int i;
1542
1555
int wrapLineIdx = 0 ;
1556
+ int wrapLineCacheIdx = 0 ;
1543
1557
int size = d->m_pDiff3LineVector ->size ();
1544
1558
pp.setMaxNofSteps (size);
1545
1559
for ( i=0 ; i<size; ++i )
1546
1560
{
1547
1561
pp.setInformation ( i18n (" Word wrap" ), double (i)/size, false );
1548
1562
if ( pp.wasCancelled () )
1549
- break ;
1563
+ return ;
1550
1564
1551
- QString s = d->getString ( i );
1552
- QTextLayout textLayout ( s, font (), this );
1553
- d->prepareTextLayout ( textLayout, true , visibleTextWidth );
1554
- int linesNeeded = textLayout.lineCount ();
1555
- if ( wrapLineVectorSize > 0 )
1565
+ int linesNeeded = 0 ;
1566
+ if ( wrapLineVectorSize==0 )
1556
1567
{
1568
+ QString s = d->getString ( i );
1569
+ QTextLayout textLayout ( s, font (), this );
1570
+ d->prepareTextLayout ( textLayout, true , visibleTextWidth );
1571
+ linesNeeded = textLayout.lineCount ();
1557
1572
for ( int l=0 ; l<linesNeeded; ++l )
1558
1573
{
1559
- Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector [ wrapLineIdx + l ];
1574
+ // Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector[ wrapLineIdx + l ];
1560
1575
QTextLine line = textLayout.lineAt (l);
1561
- pDiff3WrapLine->wrapLineOffset = line.textStart ();
1562
- pDiff3WrapLine->wrapLineLength = line.textLength ();
1576
+ d->m_wrapLineCache .push_back ( DiffTextWindowData::WrapLineCacheData (i,line.textStart (),line.textLength ()) );
1577
+ }
1578
+ }
1579
+ else if ( wrapLineVectorSize > 0 )
1580
+ {
1581
+ while ( wrapLineCacheIdx<d->m_wrapLineCache .count () &&
1582
+ d->m_wrapLineCache [wrapLineCacheIdx].m_d3LineIdx <i )
1583
+ ++wrapLineCacheIdx;
1584
+ int l=0 ;
1585
+ while ( wrapLineCacheIdx<d->m_wrapLineCache .count () &&
1586
+ d->m_wrapLineCache [wrapLineCacheIdx].m_d3LineIdx ==i )
1587
+ {
1588
+ Diff3WrapLine* pDiff3WrapLine = &d->m_diff3WrapLineVector [ wrapLineIdx + l ];
1589
+ pDiff3WrapLine->wrapLineOffset = d->m_wrapLineCache [wrapLineCacheIdx].m_textStart ;
1590
+ pDiff3WrapLine->wrapLineLength = d->m_wrapLineCache [wrapLineCacheIdx].m_textLength ;
1591
+ ++l;
1592
+ ++wrapLineCacheIdx;
1563
1593
}
1594
+ linesNeeded = l;
1564
1595
}
1565
1596
1566
1597
Diff3Line& d3l = *(*d->m_pDiff3LineVector )[i];
0 commit comments