diff options
author | Zufu Liu <unknown> | 2021-05-08 14:41:20 +1000 |
---|---|---|
committer | Zufu Liu <unknown> | 2021-05-08 14:41:20 +1000 |
commit | 9547147a9ca0f258d5d25a0b0b116373ed29533f (patch) | |
tree | 479c3f194faeec5a21deaf36433334f4d130a884 | |
parent | f8dd521303ff7e201a3ee37a72d7d56d63e161c7 (diff) | |
download | scintilla-mirror-9547147a9ca0f258d5d25a0b0b116373ed29533f.tar.gz |
Feature [feature-requests:1373]. Add methods for refining idle task durations.
-rw-r--r-- | src/Document.cxx | 18 | ||||
-rw-r--r-- | src/Document.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index ffbf8f557..21d492a8e 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -107,6 +107,10 @@ double ActionDuration::Duration() const noexcept { return duration; } +size_t ActionDuration::ActionsInAllowedTime(double secondsAllowed) const noexcept { + return std::lround(secondsAllowed / Duration()); +} + Document::Document(int options) : cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0, (options & SC_DOCUMENTOPTION_TEXT_LARGE) != 0), durationStyleOneLine(0.00001, 0.000001, 0.0001) { @@ -474,6 +478,20 @@ Sci::Line Document::LineFromPositionIndex(Sci::Position pos, int lineCharacterIn return cb.LineFromPositionIndex(pos, lineCharacterIndex); } +Sci::Line Document::LineFromPositionAfter(Sci::Line line, Sci::Position length) const noexcept { + const Sci::Position posAfter = cb.LineStart(line) + length; + if (posAfter >= LengthNoExcept()) { + return LinesTotal(); + } + const Sci::Line lineAfter = SciLineFromPosition(posAfter); + if (lineAfter > line) { + return lineAfter; + } else { + // Want to make some progress so return next line + return lineAfter + 1; + } +} + int SCI_METHOD Document::SetLevel(Sci_Position line, int level) { const int prev = Levels()->SetLevel(line, level, LinesTotal()); if (prev != level) { diff --git a/src/Document.h b/src/Document.h index e2d9eddce..690871ba8 100644 --- a/src/Document.h +++ b/src/Document.h @@ -207,6 +207,7 @@ public: ActionDuration(double duration_, double minDuration_, double maxDuration_) noexcept; void AddSample(size_t numberActions, double durationOfActions) noexcept; double Duration() const noexcept; + size_t ActionsInAllowedTime(double secondsAllowed) const noexcept; }; /** @@ -416,6 +417,7 @@ public: Sci::Position VCHomePosition(Sci::Position position) const; Sci::Position IndexLineStart(Sci::Line line, int lineCharacterIndex) const noexcept; Sci::Line LineFromPositionIndex(Sci::Position pos, int lineCharacterIndex) const noexcept; + Sci::Line LineFromPositionAfter(Sci::Line line, Sci::Position length) const noexcept; int SCI_METHOD SetLevel(Sci_Position line, int level) override; int SCI_METHOD GetLevel(Sci_Position line) const override; |