diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e50484810..89e898d47 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2600,7 +2600,6 @@ BOOL Notepad_plus::notify(SCNotification *notification) break; case SCN_ZOOM: - notifyView->setLineNumberWidth(notifyView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER)); break; case SCN_MACRORECORD: @@ -2609,6 +2608,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_PAINTED: { + notifyView->updateLineNumberWidth(); if (_syncInfo.doSync()) doSynScorll(HWND(notification->nmhdr.hwndFrom)); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 3eac2553c..8dc82f8b7 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -32,8 +32,6 @@ const int ScintillaEditView::_SC_MARGE_SYBOLE = 1; const int ScintillaEditView::_SC_MARGE_FOLDER = 2; const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3; -const int ScintillaEditView::_MARGE_LINENUMBER_NB_CHIFFRE = 5; - WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL; /* SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree @@ -1394,9 +1392,6 @@ void ScintillaEditView::activateBuffer(BufferID buffer) itoa(numLines, numLineStr, 10); int nbDigit = strlen(numLineStr); - if (increaseMaxNbDigit(nbDigit)) - setLineNumberWidth(hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER)); - runMarkers(true, 0, true, false); return; //all done } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 0f72cfccb..cda6c9a82 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -149,7 +149,7 @@ class ScintillaEditView : public Window public: ScintillaEditView() : Window(), _pScintillaFunc(NULL),_pScintillaPtr(NULL), - _folderStyle(FOLDER_STYLE_BOX), _maxNbDigit(_MARGE_LINENUMBER_NB_CHIFFRE), _wrapRestoreNeeded(false) + _folderStyle(FOLDER_STYLE_BOX), _lineNumbersShown(false), _wrapRestoreNeeded(false) { ++_refCount; }; @@ -247,11 +247,9 @@ public: static const int _SC_MARGE_FOLDER; static const int _SC_MARGE_MODIFMARKER; - static const int _MARGE_LINENUMBER_NB_CHIFFRE; - void showMargin(int whichMarge, bool willBeShowed = true) { if (whichMarge == _SC_MARGE_LINENUMBER) - setLineNumberWidth(willBeShowed); + showLineNumbersMargin(willBeShowed); else { int width = 3; @@ -380,11 +378,41 @@ public: void setLineIndent(int line, int indent) const; - void setLineNumberWidth(bool willBeShowed = true) { - // The 4 here allows for spacing: 1 poxel on left and 3 on right. - int pixelWidth = int((willBeShowed)?(8 + _maxNbDigit * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8")):0); - execute(SCI_SETMARGINWIDTHN, 0, pixelWidth); - }; + void showLineNumbersMargin(bool show){ + if (show == _lineNumbersShown) return; + _lineNumbersShown = show; + if (show) + { + updateLineNumberWidth(); + } + else + { + execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, 0); + } + } + + void updateLineNumberWidth() { + if (_lineNumbersShown) + { + int linesVisible = (int) execute(SCI_LINESONSCREEN); + if (linesVisible) + { + int firstVisibleLineVis = (int) execute(SCI_GETFIRSTVISIBLELINE); + int lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1; + int i = 0; + while (lastVisibleLineVis) + { + lastVisibleLineVis /= 10; + i++; + } + i = max(i, 3); + { + int pixelWidth = int(8 + i * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8")); + execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth); + } + } + } + }; void setCurrentLineHiLiting(bool isHiliting, COLORREF bgColor) const { execute(SCI_SETCARETLINEVISIBLE, isHiliting); @@ -448,15 +476,6 @@ public: void foldCurrentPos(bool mode); int getCodepage() const {return _codepage;}; - bool increaseMaxNbDigit(int newValue) { - if (newValue > _maxNbDigit) - { - _maxNbDigit = newValue; - return true; - } - return false; - }; - NppParameters * getParameter() { return _pParameter; }; @@ -579,7 +598,7 @@ protected: int _codepage; int _oemCodepage; - int _maxNbDigit; // For Line Number Marge + bool _lineNumbersShown; bool _wrapRestoreNeeded;