diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index de426304d..bcc7fce0e 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2521,6 +2521,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch allSessionFilesLoaded = false; } } + if (mainIndex2Update != -1) { _isFolding = true; diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index d1584c5bf..02032503a 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -2592,6 +2592,27 @@ bool ScintillaEditView::isCurrentLineFolded() const void ScintillaEditView::fold(size_t line, bool mode, bool shouldBeNotified/* = true*/) { + auto endStyled = execute(SCI_GETENDSTYLED); + auto len = execute(SCI_GETTEXTLENGTH); + + if (endStyled < len) + execute(SCI_COLOURISE, 0, -1); +/* +The method ScintillaEditView::fold() is called not only on manual folding by the users, but also on: + +1. startup's loading session to restore the folding state programmatically. +2. after startup, switching among the documents to restore the folding state programmatically. + +The above lines are important for the case 1. + +However, these lines are necessary only on the first load of each file after the startup of Notepad++. +"execute(SCI_COLOURISE, 0, -1);" needs to be run for once (the case 1), not twice or more (the case 2). + +So if there's a way to detect if a document has been run "execute(SCI_COLOURISE, 0, -1);" once (in the case 1), +and don't run it again (the case 2), it will save the time to switch among the document. +*/ + + intptr_t headerLine; auto level = execute(SCI_GETFOLDLEVEL, line);