[ENHANCEMENT] (Author: Andreas Jonsson) Enhance folding performance on large document.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@936 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2012-08-09 00:17:05 +00:00
parent 78a38c1c28
commit 301492a3a6
3 changed files with 20 additions and 9 deletions

View File

@ -1922,13 +1922,8 @@ void Notepad_plus::addHotSpot(bool docIsModifing)
} }
} }
int startPos = 0, endPos = -1;
int firstVisibleLine = _pEditView->execute(SCI_GETFIRSTVISIBLELINE); _pEditView->getVisibleStartAndEndPosition(&startPos, &endPos);
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)));
_pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX);

View File

@ -1577,7 +1577,9 @@ void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask)
void ScintillaEditView::collapse(int level2Collapse, bool mode) void ScintillaEditView::collapse(int level2Collapse, bool mode)
{ {
// The following code is needed : // 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 : // according to the Scitilla document :
// This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) // 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. // 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) void ScintillaEditView::fold(int line, bool mode)
{ {
// The following code is needed : // 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 : // according to the Scitilla document :
// This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) // 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. // 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); 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) char * ScintillaEditView::getWordFromRange(char * txt, int size, int pos1, int pos2)
{ {
if (!size) if (!size)

View File

@ -256,6 +256,7 @@ public:
return (range.cpMax - range.cpMin); return (range.cpMax - range.cpMin);
}; };
void getVisibleStartAndEndPosition(int * startPos, int * endPos);
char * getWordFromRange(char * txt, int size, int pos1, int pos2); char * getWordFromRange(char * txt, int size, int pos1, int pos2);
char * getSelectedText(char * txt, int size, bool expand = true); char * getSelectedText(char * txt, int size, bool expand = true);
char * getWordOnCaretPos(char * txt, int size); char * getWordOnCaretPos(char * txt, int size);