From e61cd5419bc74260616305a245a5cc2cba9784bc Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 15 Oct 2018 09:13:17 +1100 Subject: 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. --- src/Editor.cxx | 14 ++++++++++++-- src/Editor.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') 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 #include #include +#include #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(secondsAllowed / durationWrapOneLine.Duration()), + LinesOnScreen() + 50, static_cast(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(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; -- cgit v1.2.3