From e93a47975d317f59df0fdcca7cee95b6ab4ff33f Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 27 Mar 2018 19:35:55 +1100 Subject: Return a FillResult struct from RunStyles::FillRange instead of modifying arguments as that is clumsy when converting types. --- src/Decoration.cxx | 6 +++--- src/Decoration.h | 4 ++-- src/Document.cxx | 8 ++++---- src/RunStyles.cxx | 17 +++++++++-------- src/RunStyles.h | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Decoration.cxx b/src/Decoration.cxx index 5a653a589..0470f26f9 100644 --- a/src/Decoration.cxx +++ b/src/Decoration.cxx @@ -90,18 +90,18 @@ void DecorationList::SetCurrentValue(int value) { currentValue = value ? value : 1; } -bool DecorationList::FillRange(Sci::Position &position, int value, Sci::Position &fillLength) { +FillResult DecorationList::FillRange(Sci::Position position, int value, Sci::Position fillLength) { if (!current) { current = DecorationFromIndicator(currentIndicator); if (!current) { current = Create(currentIndicator, lengthDocument); } } - const bool changed = current->rs.FillRange(position, value, fillLength); + const FillResult fr = current->rs.FillRange(position, value, fillLength); if (current->Empty()) { Delete(currentIndicator); } - return changed; + return fr; } void DecorationList::InsertSpace(Sci::Position position, Sci::Position insertLength) { diff --git a/src/Decoration.h b/src/Decoration.h index 0d799920e..86397fde1 100644 --- a/src/Decoration.h +++ b/src/Decoration.h @@ -51,8 +51,8 @@ public: void SetCurrentValue(int value); int GetCurrentValue() const { return currentValue; } - // Returns true if some values may have changed - bool FillRange(Sci::Position &position, int value, Sci::Position &fillLength); + // Returns with changed=true if some values may have changed + FillResult FillRange(Sci::Position position, int value, Sci::Position fillLength); void InsertSpace(Sci::Position position, Sci::Position insertLength); void DeleteRange(Sci::Position position, Sci::Position deleteLength); diff --git a/src/Document.cxx b/src/Document.cxx index cb2892c96..e0373a752 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2243,11 +2243,11 @@ void SCI_METHOD Document::DecorationSetCurrentIndicator(int indicator) { } void SCI_METHOD Document::DecorationFillRange(Sci_Position position, int value, Sci_Position fillLength) { - Sci::Position sciPosition = static_cast(position); - Sci::Position sciFillLength = static_cast(fillLength); - if (decorations.FillRange(sciPosition, value, sciFillLength)) { + const FillResult fr = decorations.FillRange( + static_cast(position), value, static_cast(fillLength)); + if (fr.changed) { const DocModification mh(SC_MOD_CHANGEINDICATOR | SC_PERFORMED_USER, - sciPosition, sciFillLength); + fr.position, fr.fillLength); NotifyModified(mh); } } diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index fa8844bfe..03692f673 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -126,13 +126,14 @@ DISTANCE RunStyles::EndRun(DISTANCE position) const { } template -bool RunStyles::FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength) { +FillResult RunStyles::FillRange(DISTANCE position, STYLE value, DISTANCE fillLength) { + const FillResult resultNoChange{false, position, fillLength}; if (fillLength <= 0) { - return false; + return resultNoChange; } DISTANCE end = position + fillLength; if (end > Length()) { - return false; + return resultNoChange; } DISTANCE runEnd = RunFromPosition(end); if (styles->ValueAt(runEnd) == value) { @@ -140,7 +141,7 @@ bool RunStyles::FillRange(DISTANCE &position, STYLE value, DIST end = starts->PositionFromPartition(runEnd); if (position >= end) { // Whole range is already same as value so no action - return false; + return resultNoChange; } fillLength = end - position; } else { @@ -159,6 +160,7 @@ bool RunStyles::FillRange(DISTANCE &position, STYLE value, DIST } } if (runStart < runEnd) { + const FillResult result{ true, position, fillLength }; styles->SetValueAt(runStart, value); // Remove each old run over the range for (DISTANCE run=runStart+1; run::FillRange(DISTANCE &position, STYLE value, DIST RemoveRunIfSameAsPrevious(runStart); runEnd = RunFromPosition(end); RemoveRunIfEmpty(runEnd); - return true; + return result; } else { - return false; + return resultNoChange; } } template void RunStyles::SetValueAt(DISTANCE position, STYLE value) { - DISTANCE len = 1; - FillRange(position, value, len); + FillRange(position, value, 1); } template diff --git a/src/RunStyles.h b/src/RunStyles.h index c28621334..af2eb3ec6 100644 --- a/src/RunStyles.h +++ b/src/RunStyles.h @@ -12,6 +12,16 @@ namespace Scintilla { +// Return for RunStyles::FillRange reports if anything was changed and the +// range that was changed. This may be trimmed from the requested range +// when some of the requested range already had the requested value. +template +struct FillResult { + bool changed; + DISTANCE position; + DISTANCE fillLength; +}; + template class RunStyles { private: @@ -33,8 +43,8 @@ public: DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const; DISTANCE StartRun(DISTANCE position) const; DISTANCE EndRun(DISTANCE position) const; - // Returns true if some values may have changed - bool FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength); + // Returns changed=true if some values may have changed + FillResult FillRange(DISTANCE position, STYLE value, DISTANCE fillLength); void SetValueAt(DISTANCE position, STYLE value); void InsertSpace(DISTANCE position, DISTANCE insertLength); void DeleteAll(); -- cgit v1.2.3