diff options
author | Neil <nyamatongwe@gmail.com> | 2015-11-11 19:14:30 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-11-11 19:14:30 +1100 |
commit | fc7f7bed53a60d2d3785cf95093d388d39b2af11 (patch) | |
tree | 6b1030593ef0c6e8815c356269b8722d1109017c /src/Document.cxx | |
parent | 4a52b4ef384436f5474184588ecacf666369afa0 (diff) | |
download | scintilla-mirror-fc7f7bed53a60d2d3785cf95093d388d39b2af11.tar.gz |
Implemented idle styling. This allows painting without first styling all visible
text then styling in the background using idle-time.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r-- | src/Document.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index 9201e162f..65c63c138 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -109,6 +109,7 @@ Document::Document() { useTabs = true; tabIndents = true; backspaceUnindents = false; + durationStyleOneLine = 0.00001; matchesValid = false; regex = 0; @@ -1892,6 +1893,33 @@ void Document::EnsureStyledTo(int pos) { } } +void Document::StyleToAdjustingLineDuration(int pos) { + // Place bounds on the duration used to avoid glitches spiking it + // and so causing slow styling or non-responsive scrolling + const double minDurationOneLine = 0.000001; + const double maxDurationOneLine = 0.0001; + + // Alpha value for exponential smoothing. + // Most recent value contributes 25% to smoothed value. + const double alpha = 0.25; + + const Sci_Position lineFirst = LineFromPosition(GetEndStyled()); + ElapsedTime etStyling; + EnsureStyledTo(pos); + const double durationStyling = etStyling.Duration(); + const Sci_Position lineLast = LineFromPosition(GetEndStyled()); + if (lineLast >= lineFirst + 8) { + // Only adjust for styling multiple lines to avoid instability + const double durationOneLine = durationStyling / (lineLast - lineFirst); + durationStyleOneLine = alpha * durationOneLine + (1.0 - alpha) * durationStyleOneLine; + if (durationStyleOneLine < minDurationOneLine) { + durationStyleOneLine = minDurationOneLine; + } else if (durationStyleOneLine > maxDurationOneLine) { + durationStyleOneLine = maxDurationOneLine; + } + } +} + void Document::LexerChanged() { // Tell the watchers the lexer has changed. for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) { |