diff options
author | Neil <nyamatongwe@gmail.com> | 2018-10-15 09:13:17 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-10-15 09:13:17 +1100 |
commit | e61cd5419bc74260616305a245a5cc2cba9784bc (patch) | |
tree | ddf81f008c6676dd63a9e39f1c98f637f46076fe /src | |
parent | 9be9a1b22f7bc4126966677f6c9489dbeeccddd5 (diff) | |
download | scintilla-mirror-e61cd5419bc74260616305a245a5cc2cba9784bc.tar.gz |
Backport: Set number of lines wrapped in one go to maintain responsiveness and efficiency
by measuring speed and limiting to around 10 milliseconds.
Backport of changeset 7114:efe194662480.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 14 | ||||
-rw-r--r-- | src/Editor.h | 1 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 68a090a28..1498ce4f6 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -21,6 +21,7 @@ #include <algorithm> #include <iterator> #include <memory> +#include <chrono> #include "Platform.h" @@ -54,6 +55,7 @@ #include "MarginView.h" #include "EditView.h" #include "Editor.h" +#include "ElapsedPeriod.h" using namespace Scintilla; @@ -103,7 +105,7 @@ static inline bool IsAllSpacesOrTabs(const char *s, unsigned int len) { return true; } -Editor::Editor() { +Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) { ctrlID = 0; stylesValid = false; @@ -1533,7 +1535,12 @@ bool Editor::WrapLines(WrapScope ws) { return false; } } else if (ws == WrapScope::wsIdle) { - lineToWrapEnd = lineToWrap + LinesOnScreen() + 100; + // Try to keep time taken by wrapping reasonable so interaction remains smooth. + const double secondsAllowed = 0.01; + const Sci::Line linesInAllowedTime = Sci::clamp( + static_cast<Sci::Line>(secondsAllowed / durationWrapOneLine.Duration()), + LinesOnScreen() + 50, static_cast<Sci::Line>(0x10000)); + lineToWrapEnd = lineToWrap + linesInAllowedTime; } const Sci::Line lineEndNeedWrap = std::min(wrapPending.end, pdoc->LinesTotal()); lineToWrapEnd = std::min(lineToWrapEnd, lineEndNeedWrap); @@ -1552,6 +1559,8 @@ bool Editor::WrapLines(WrapScope ws) { if (surface) { //Platform::DebugPrintf("Wraplines: scope=%0d need=%0d..%0d perform=%0d..%0d\n", ws, wrapPending.start, wrapPending.end, lineToWrap, lineToWrapEnd); + const Sci::Line linesBeingWrapped = lineToWrapEnd - lineToWrap; + ElapsedPeriod epWrapping; while (lineToWrap < lineToWrapEnd) { if (WrapOneLine(surface, lineToWrap)) { wrapOccurred = true; @@ -1559,6 +1568,7 @@ bool Editor::WrapLines(WrapScope ws) { wrapPending.Wrapped(lineToWrap); lineToWrap++; } + durationWrapOneLine.AddSample(linesBeingWrapped, epWrapping.Duration()); goodTopLine = pcs->DisplayFromDoc(lineDocTop) + std::min( subLineTop, static_cast<Sci::Line>(pcs->GetHeight(lineDocTop)-1)); diff --git a/src/Editor.h b/src/Editor.h index 428211a58..55b6f56aa 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -250,6 +250,7 @@ protected: // ScintillaBase subclass needs access to much of Editor // Wrapping support WrapPending wrapPending; + ActionDuration durationWrapOneLine; bool convertPastes; |