diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Decoration.cxx | 6 | ||||
| -rw-r--r-- | src/Decoration.h | 4 | ||||
| -rw-r--r-- | src/Document.cxx | 8 | ||||
| -rw-r--r-- | src/RunStyles.cxx | 17 | ||||
| -rw-r--r-- | src/RunStyles.h | 14 | 
5 files changed, 30 insertions, 19 deletions
| 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<Sci::Position> 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<Sci::Position> 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<Sci::Position> 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<Sci::Position>(position); -	Sci::Position sciFillLength = static_cast<Sci::Position>(fillLength); -	if (decorations.FillRange(sciPosition, value, sciFillLength)) { +	const FillResult<Sci::Position> fr = decorations.FillRange( +		static_cast<Sci::Position>(position), value, static_cast<Sci::Position>(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<DISTANCE, STYLE>::EndRun(DISTANCE position) const {  }  template <typename DISTANCE, typename STYLE> -bool RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength) { +FillResult<DISTANCE> RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE position, STYLE value, DISTANCE fillLength) { +	const FillResult<DISTANCE> 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<DISTANCE, STYLE>::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<DISTANCE, STYLE>::FillRange(DISTANCE &position, STYLE value, DIST  		}  	}  	if (runStart < runEnd) { +		const FillResult<DISTANCE> result{ true, position, fillLength };  		styles->SetValueAt(runStart, value);  		// Remove each old run over the range  		for (DISTANCE run=runStart+1; run<runEnd; run++) { @@ -169,16 +171,15 @@ bool RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE &position, STYLE value, DIST  		RemoveRunIfSameAsPrevious(runStart);  		runEnd = RunFromPosition(end);  		RemoveRunIfEmpty(runEnd); -		return true; +		return result;  	} else { -		return false; +		return resultNoChange;  	}  }  template <typename DISTANCE, typename STYLE>  void RunStyles<DISTANCE, STYLE>::SetValueAt(DISTANCE position, STYLE value) { -	DISTANCE len = 1; -	FillRange(position, value, len); +	FillRange(position, value, 1);  }  template <typename DISTANCE, typename STYLE> 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 <typename DISTANCE> +struct FillResult { +	bool changed; +	DISTANCE position; +	DISTANCE fillLength; +}; +  template <typename DISTANCE, typename STYLE>  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<DISTANCE> FillRange(DISTANCE position, STYLE value, DISTANCE fillLength);  	void SetValueAt(DISTANCE position, STYLE value);  	void InsertSpace(DISTANCE position, DISTANCE insertLength);  	void DeleteAll(); | 
