diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 07e02a11..6c4bcba9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1922,13 +1922,8 @@ void Notepad_plus::addHotSpot(bool docIsModifing) } } - - int firstVisibleLine = _pEditView->execute(SCI_GETFIRSTVISIBLELINE); - int startPos = _pEditView->execute(SCI_POSITIONFROMLINE, _pEditView->execute(SCI_DOCLINEFROMVISIBLE, firstVisibleLine)); - int linesOnScreen = _pEditView->execute(SCI_LINESONSCREEN); - int lineCount = _pEditView->execute(SCI_GETLINECOUNT); - int endPos = _pEditView->execute(SCI_POSITIONFROMLINE,_pEditView->execute(SCI_DOCLINEFROMVISIBLE, firstVisibleLine + min(linesOnScreen, lineCount))); - + int startPos = 0, endPos = -1; + _pEditView->getVisibleStartAndEndPosition(&startPos, &endPos); _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index fbd73768..a368465a 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1577,7 +1577,9 @@ void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask) void ScintillaEditView::collapse(int level2Collapse, bool mode) { // The following code is needed : - execute(SCI_COLOURISE, 0, -1); + int startPos = 0, endPos = -1; + getVisibleStartAndEndPosition(&startPos, &endPos); + execute(SCI_COLOURISE, startPos, endPos); // according to the Scitilla document : // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. @@ -1612,7 +1614,9 @@ void ScintillaEditView::foldCurrentPos(bool mode) void ScintillaEditView::fold(int line, bool mode) { // The following code is needed : - execute(SCI_COLOURISE, 0, -1); + int startPos = 0, endPos = -1; + getVisibleStartAndEndPosition(&startPos, &endPos); + execute(SCI_COLOURISE, startPos, endPos); // according to the Scitilla document : // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. @@ -1730,6 +1734,17 @@ void ScintillaEditView::replaceSelWith(const char * replaceText) execute(SCI_REPLACESEL, 0, (WPARAM)replaceText); } +void ScintillaEditView::getVisibleStartAndEndPosition(int * startPos, int * endPos) +{ + assert(startPos != nullptr && endPos != nullptr); + + int firstVisibleLine = execute(SCI_GETFIRSTVISIBLELINE); + *startPos = execute(SCI_POSITIONFROMLINE, execute(SCI_DOCLINEFROMVISIBLE, firstVisibleLine)); + int linesOnScreen = execute(SCI_LINESONSCREEN); + int lineCount = execute(SCI_GETLINECOUNT); + *endPos = execute(SCI_POSITIONFROMLINE, execute(SCI_DOCLINEFROMVISIBLE, firstVisibleLine + min(linesOnScreen, lineCount))); +} + char * ScintillaEditView::getWordFromRange(char * txt, int size, int pos1, int pos2) { if (!size) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 40490de0..94839a00 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -256,6 +256,7 @@ public: return (range.cpMax - range.cpMin); }; + void getVisibleStartAndEndPosition(int * startPos, int * endPos); char * getWordFromRange(char * txt, int size, int pos1, int pos2); char * getSelectedText(char * txt, int size, bool expand = true); char * getWordOnCaretPos(char * txt, int size);