diff options
| author | nyamatongwe <unknown> | 2009-07-14 03:28:22 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2009-07-14 03:28:22 +0000 | 
| commit | 03cca7be7b6f7e1a2899c01bf50a7a61f9be1a21 (patch) | |
| tree | 084abdf19b98d1571d40853b503bd05b723c243e /src/Selection.cxx | |
| parent | 1231cf6c2eecdf6fdaba67c13d82a7cfb251ccbb (diff) | |
| download | scintilla-mirror-03cca7be7b6f7e1a2899c01bf50a7a61f9be1a21.tar.gz | |
Added controls for enabling multiple selection and multiple selection
typing. Renamed multiline options to reflect use on multiple selections.
Using std::vector for selections.
Diffstat (limited to 'src/Selection.cxx')
| -rw-r--r-- | src/Selection.cxx | 53 | 
1 files changed, 20 insertions, 33 deletions
| diff --git a/src/Selection.cxx b/src/Selection.cxx index d9c59cdb1..eada57d5e 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -7,6 +7,8 @@  #include <stdlib.h> +#include <vector> +  #include "Platform.h"  #include "Scintilla.h" @@ -128,13 +130,9 @@ SelectionSegment SelectionRange::Intersect(SelectionSegment check) const {  	}  } -bool SelectionRange::Trim(SelectionPosition startPos, SelectionPosition endPos) { -	SelectionPosition startRange = startPos; -	SelectionPosition endRange = endPos; -	if (startPos > endPos) { -		startRange = endPos; -		endRange = startPos; -	} +bool SelectionRange::Trim(SelectionRange range) { +	SelectionPosition startRange = range.Start(); +	SelectionPosition endRange = range.End();  	SelectionPosition start = Start();  	SelectionPosition end = End();  	PLATFORM_ASSERT(start <= end); @@ -178,24 +176,11 @@ void SelectionRange::MinimizeVirtualSpace() {  	}  } -void Selection::Allocate() { -	if (nRanges >= allocated) { -		size_t allocateNew = (allocated + 1) * 2; -		SelectionRange *rangesNew = new SelectionRange[allocateNew]; -		for (size_t r=0; r<Count(); r++) -			rangesNew[r] = ranges[r]; -		delete []ranges; -		ranges = rangesNew; -		allocated = allocateNew; -	} -} - -Selection::Selection() : ranges(0), allocated(0), nRanges(0), mainRange(0), moveExtends(false), selType(selStream) { +Selection::Selection() : ranges(0), nRanges(0), mainRange(0), moveExtends(false), selType(selStream) {  	AddSelection(SelectionPosition(0));  }  Selection::~Selection() { -	delete []ranges;  }  bool Selection::IsRectangular() const { @@ -281,9 +266,9 @@ void Selection::MovePositions(bool insertion, int startChange, int length) {  	}  } -void Selection::TrimSelection(SelectionPosition startPos, SelectionPosition endPos) { +void Selection::TrimSelection(SelectionRange range) {  	for (size_t i=0; i<nRanges;) { -		if ((i != mainRange) && (ranges[i].Trim(startPos, endPos))) { +		if ((i != mainRange) && (ranges[i].Trim(range))) {  			// Trimmed to empty so remove  			for (size_t j=i;j<nRanges-1;j++) {  				ranges[j] = ranges[j+1]; @@ -297,21 +282,23 @@ void Selection::TrimSelection(SelectionPosition startPos, SelectionPosition endP  	}  } -void Selection::AddSelection(SelectionPosition spPos) { -	Allocate(); -	TrimSelection(spPos, spPos); -	ranges[nRanges] = SelectionRange(spPos); +void Selection::AddSelection(SelectionRange range) { +	ranges.resize(nRanges + 1); +	TrimSelection(range); +	ranges[nRanges] = range;  	mainRange = nRanges;  	nRanges++;  } +void Selection::AddSelection(SelectionPosition spPos) { +	AddSelection(SelectionRange(spPos, spPos)); +} +  void Selection::AddSelection(SelectionPosition spStartPos, SelectionPosition spEndPos, bool anchorLeft) { -	Allocate(); -	TrimSelection(spStartPos, spEndPos); -	ranges[nRanges].caret = anchorLeft ? spEndPos : spStartPos; -	ranges[nRanges].anchor = anchorLeft ? spStartPos : spEndPos; -	mainRange = nRanges; -	nRanges++; +	if (anchorLeft) +		AddSelection(SelectionRange(spEndPos, spStartPos)); +	else +		AddSelection(SelectionRange(spStartPos, spEndPos));  }  int Selection::CharacterInSelection(int posCharacter) const { | 
