Fix inaccurate line margin update with word wrap enabled
And improve the performance of line margin update.
This commit is contained in:
parent
00841d5a22
commit
fe18e41d5d
|
@ -2723,32 +2723,28 @@ void ScintillaEditView::updateLineNumberWidth()
|
||||||
auto firstVisibleLineVis = execute(SCI_GETFIRSTVISIBLELINE);
|
auto firstVisibleLineVis = execute(SCI_GETFIRSTVISIBLELINE);
|
||||||
auto lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1;
|
auto lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1;
|
||||||
|
|
||||||
if (execute(SCI_GETWRAPMODE) != SC_WRAP_NONE)
|
auto lastVisibleLineDoc = execute(SCI_DOCLINEFROMVISIBLE, lastVisibleLineVis);
|
||||||
|
int nbDigits = 0;
|
||||||
|
if (lastVisibleLineDoc >= 1 && lastVisibleLineDoc <= 9) nbDigits = 1;
|
||||||
|
else if (lastVisibleLineDoc >= 10 && lastVisibleLineDoc <= 99) nbDigits = 2;
|
||||||
|
else if (lastVisibleLineDoc >= 100 && lastVisibleLineDoc <= 999) nbDigits = 3;
|
||||||
|
else if (lastVisibleLineDoc >= 1000 && lastVisibleLineDoc <= 9999) nbDigits = 4;
|
||||||
|
else if (lastVisibleLineDoc >= 10000 && lastVisibleLineDoc <= 99999) nbDigits = 5;
|
||||||
|
else if (lastVisibleLineDoc >= 100000 && lastVisibleLineDoc <= 999999) nbDigits = 6;
|
||||||
|
else // rare case
|
||||||
{
|
{
|
||||||
auto numLinesDoc = execute(SCI_GETLINECOUNT);
|
nbDigits = 7;
|
||||||
auto prevLineDoc = execute(SCI_DOCLINEFROMVISIBLE, firstVisibleLineVis);
|
lastVisibleLineDoc /= 1000000;
|
||||||
for (auto i = firstVisibleLineVis + 1; i <= lastVisibleLineVis; ++i)
|
|
||||||
|
while (lastVisibleLineDoc)
|
||||||
{
|
{
|
||||||
auto lineDoc = execute(SCI_DOCLINEFROMVISIBLE, i);
|
lastVisibleLineDoc /= 10;
|
||||||
if (lineDoc == numLinesDoc)
|
++nbDigits;
|
||||||
break;
|
|
||||||
if (lineDoc == prevLineDoc)
|
|
||||||
lastVisibleLineVis++;
|
|
||||||
prevLineDoc = lineDoc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lastVisibleLineDoc = execute(SCI_DOCLINEFROMVISIBLE, lastVisibleLineVis);
|
nbDigits = max(nbDigits, 3);
|
||||||
int i = 0;
|
auto pixelWidth = 8 + nbDigits * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8"));
|
||||||
|
|
||||||
while (lastVisibleLineDoc)
|
|
||||||
{
|
|
||||||
lastVisibleLineDoc /= 10;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = max(i, 3);
|
|
||||||
auto pixelWidth = 8 + i * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8"));
|
|
||||||
execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth);
|
execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue