diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Editor.cxx | 55 | ||||
| -rw-r--r-- | src/Editor.h | 6 | ||||
| -rw-r--r-- | src/PositionCache.cxx | 2 | ||||
| -rw-r--r-- | src/ScintillaBase.cxx | 2 | ||||
| -rw-r--r-- | src/Selection.cxx | 53 | ||||
| -rw-r--r-- | src/Selection.h | 9 | 
6 files changed, 71 insertions, 56 deletions
| diff --git a/src/Editor.cxx b/src/Editor.cxx index e8774c698..5effff931 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -11,6 +11,7 @@  #include <ctype.h>  #include <string> +#include <vector>  // With Borland C++ 5.5, including <string> includes Windows.h leading to defining  // FindText to FindTextA which makes calls here to Document::FindText fail. @@ -146,8 +147,9 @@ Editor::Editor() {  	verticalScrollBarVisible = true;  	endAtLastLine = true;  	caretSticky = false; -	multiLineCaret = false; -	multiLineCaretBlinks = true; +	multipleSelection = false; +	additionalSelectionTyping = false; +	additionalCaretsBlink = true;  	virtualSpaceOptions = SCVS_NONE;  	virtualSpaceOptions = SCVS_USERACCESSIBLE; @@ -3104,7 +3106,7 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS  					xposCaret += ll->wrapIndent;  			}  			if ((xposCaret >= 0) && (vsDraw.caretWidth > 0) && (vsDraw.caretStyle != CARETSTYLE_INVISIBLE) && -			        ((posDrag.IsValid()) || ((caret.active && caret.on) || (!multiLineCaretBlinks && !mainCaret)))) { +			        ((posDrag.IsValid()) || ((caret.active && caret.on) || (!additionalCaretsBlink && !mainCaret)))) {  				bool caretAtEOF = false;  				bool caretAtEOL = false;  				bool drawBlockCaret = false; @@ -3663,8 +3665,18 @@ void Editor::AddChar(char ch) {  	AddCharUTF(s, 1);  } +void Editor::FilterSelections() { +	if (!additionalSelectionTyping && (sel.Count() > 1)) { +		SelectionRange rangeOnly = sel.RangeMain(); +		InvalidateSelection(rangeOnly, true); +		sel.EmptyRanges(); +		sel.AddSelection(rangeOnly); +	} +} +  // AddCharUTF inserts an array of bytes which may or may not be in UTF-8.  void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { +	FilterSelections();  	{  		UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty() || inOverstrike);  		for (size_t r=0; r<sel.Count(); r++) { @@ -3757,6 +3769,7 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {  }  void Editor::ClearSelection() { +	FilterSelections();  	UndoGroup ug(pdoc);  	for (size_t r=0; r<sel.Count(); r++) {  		if (!sel.Range(r).Empty()) { @@ -3915,6 +3928,7 @@ void Editor::DelChar() {  }  void Editor::DelCharBack(bool allowLineStartDeletion) { +	FilterSelections();  	if (sel.IsRectangular())  		allowLineStartDeletion = false;  	UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty()); @@ -3928,7 +3942,7 @@ void Editor::DelCharBack(bool allowLineStartDeletion) {  					int lineCurrentPos = pdoc->LineFromPosition(sel.Range(r).caret.Position());  					if (allowLineStartDeletion || (pdoc->LineStart(lineCurrentPos) != sel.Range(r).caret.Position())) {  						if (pdoc->GetColumn(sel.Range(r).caret.Position()) <= pdoc->GetLineIndentation(lineCurrentPos) && -						        pdoc->GetColumn(sel.Range(r).caret.Position()) > 0 && pdoc->backspaceUnindents) { +								pdoc->GetColumn(sel.Range(r).caret.Position()) > 0 && pdoc->backspaceUnindents) {  							UndoGroup ugInner(pdoc, !ug.Needed());  							int indentation = pdoc->GetLineIndentation(lineCurrentPos);  							int indentationStep = pdoc->IndentSize(); @@ -5638,7 +5652,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b  			SetMouseCapture(true);  			if (inDragDrop != ddInitial) {  				SetDragPosition(SelectionPosition(invalidPosition)); -				if (ctrl) { +				if (ctrl && multipleSelection) {  					InvalidateSelection(SelectionRange(newPos), true);  					sel.AddSelection(newPos);  				} else if (!shift) { @@ -5749,9 +5763,10 @@ void Editor::ButtonMove(Point pt) {  					sel.Rectangular() = SelectionRange(movePos, sel.Rectangular().anchor);  					SetSelection(movePos, sel.RangeMain().anchor);  				} else if (sel.Count() > 1) { -					sel.TrimSelection(sel.RangeMain().anchor, movePos); -					sel.RangeMain() = SelectionRange(movePos, sel.RangeMain().anchor); -					InvalidateSelection(SelectionRange(movePos, sel.RangeMain().anchor), true); +					SelectionRange range(movePos, sel.RangeMain().anchor); +					sel.TrimSelection(range); +					sel.RangeMain() = range; +					InvalidateSelection(range, true);  				} else {  					SetSelection(movePos, sel.RangeMain().anchor);  				} @@ -8123,21 +8138,29 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  		pdoc->AddUndoAction(wParam, lParam & UNDO_MAY_COALESCE);  		break; -	case SCI_SETMULTILINECARET: -		multiLineCaret = wParam != 0; +	case SCI_SETMULTIPLESELECTION: +		multipleSelection = wParam != 0; +		InvalidateCaret(); +		break; + +	case SCI_GETMULTIPLESELECTION: +		return multipleSelection; + +	case SCI_SETADDITIONALSELECTIONTYPING: +		additionalSelectionTyping = wParam != 0;  		InvalidateCaret();  		break; -	case SCI_GETMULTILINECARET: -		return multiLineCaret; +	case SCI_GETADDITIONALSELECTIONTYPING: +		return additionalSelectionTyping; -	case SCI_SETMULTILINECARETBLINKS: -		multiLineCaretBlinks = wParam != 0; +	case SCI_SETADDITIONALCARETSBLINK: +		additionalCaretsBlink = wParam != 0;  		InvalidateCaret();  		break; -	case SCI_GETMULTILINECARETBLINKS: -		return multiLineCaretBlinks; +	case SCI_GETADDITIONALCARETSBLINK: +		return additionalCaretsBlink;  	case SCI_GETSELECTIONS:  		return sel.Count(); diff --git a/src/Editor.h b/src/Editor.h index 79746477e..8f1ca9b7c 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -140,8 +140,9 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	bool verticalScrollBarVisible;  	bool endAtLastLine;  	bool caretSticky; -	bool multiLineCaret; -	bool multiLineCaretBlinks; +	bool multipleSelection; +	bool additionalSelectionTyping; +	bool additionalCaretsBlink;  	int virtualSpaceOptions; @@ -351,6 +352,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void SetScrollBars();  	void ChangeSize(); +	void FilterSelections();  	int InsertSpace(int position, unsigned int spaces);  	void AddChar(char ch);  	virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index d3e19d4f4..580a1797c 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -10,6 +10,8 @@  #include <stdio.h>  #include <ctype.h> +#include <vector> +  #include "Platform.h"  #include "Scintilla.h" diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 0d25b248c..9247fce72 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -10,6 +10,8 @@  #include <stdio.h>  #include <ctype.h> +#include <vector> +  #include "Platform.h"  #include "Scintilla.h" 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 { diff --git a/src/Selection.h b/src/Selection.h index 6fe828a2c..e98709312 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -116,19 +116,17 @@ struct SelectionRange {  	SelectionPosition End() const {  		return (anchor < caret) ? caret : anchor;  	} -	bool Trim(SelectionPosition startPos, SelectionPosition endPos); +	bool Trim(SelectionRange range);  	// If range is all virtual collapse to start of virtual space  	void MinimizeVirtualSpace();  };  class Selection { -	SelectionRange *ranges; +	std::vector<SelectionRange> ranges;  	SelectionRange rangeRectangular; -	size_t allocated;  	size_t nRanges;  	size_t mainRange;  	bool moveExtends; -	void Allocate();  public:  	enum selTypes { noSel, selStream, selRectangle, selLines, selThin };  	selTypes selType; @@ -151,7 +149,8 @@ public:  	SelectionPosition Last() const;  	int Length() const;  	void MovePositions(bool insertion, int startChange, int length); -	void TrimSelection(SelectionPosition startPos, SelectionPosition endPos); +	void TrimSelection(SelectionRange range); +	void AddSelection(SelectionRange range);  	void AddSelection(SelectionPosition spPos);  	void AddSelection(SelectionPosition spStartPos, SelectionPosition spEndPos, bool anchorLeft);  	int CharacterInSelection(int posCharacter) const; | 
