Improve the computing of number of digit in line number margin display

This commit is contained in:
Don HO 2020-09-14 14:33:51 +02:00
parent 8e73f5d116
commit d82aba7b0c
1 changed files with 3 additions and 7 deletions

View File

@ -32,7 +32,6 @@
#include "ScintillaEditView.h" #include "ScintillaEditView.h"
#include "Parameters.h" #include "Parameters.h"
#include "Sorters.h" #include "Sorters.h"
#include "tchar.h"
#include "verifySignedfile.h" #include "verifySignedfile.h"
using namespace std; using namespace std;
@ -2724,10 +2723,9 @@ void ScintillaEditView::updateLineNumberWidth()
auto lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1; auto lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1;
auto lastVisibleLineDoc = execute(SCI_DOCLINEFROMVISIBLE, lastVisibleLineVis); auto lastVisibleLineDoc = execute(SCI_DOCLINEFROMVISIBLE, lastVisibleLineVis);
int nbDigits = 0;
if (lastVisibleLineDoc < 10) nbDigits = 1; int nbDigits = 3; // minimum number of digit should be 3
else if (lastVisibleLineDoc < 100) nbDigits = 2; if (lastVisibleLineDoc < 1000) {} //nbDigits = 3;
else if (lastVisibleLineDoc < 1000) nbDigits = 3;
else if (lastVisibleLineDoc < 10000) nbDigits = 4; else if (lastVisibleLineDoc < 10000) nbDigits = 4;
else if (lastVisibleLineDoc < 100000) nbDigits = 5; else if (lastVisibleLineDoc < 100000) nbDigits = 5;
else if (lastVisibleLineDoc < 1000000) nbDigits = 6; else if (lastVisibleLineDoc < 1000000) nbDigits = 6;
@ -2742,8 +2740,6 @@ void ScintillaEditView::updateLineNumberWidth()
++nbDigits; ++nbDigits;
} }
} }
nbDigits = max(nbDigits, 3);
auto pixelWidth = 8 + nbDigits * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8")); auto pixelWidth = 8 + nbDigits * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8"));
execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth); execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth);
} }