From 03cca7be7b6f7e1a2899c01bf50a7a61f9be1a21 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Tue, 14 Jul 2009 03:28:22 +0000 Subject: Added controls for enabling multiple selection and multiple selection typing. Renamed multiline options to reflect use on multiple selections. Using std::vector for selections. --- src/Editor.cxx | 55 ++++++++++++++++++++++++++++++++++++--------------- src/Editor.h | 6 ++++-- src/PositionCache.cxx | 2 ++ src/ScintillaBase.cxx | 2 ++ src/Selection.cxx | 53 +++++++++++++++++++------------------------------ src/Selection.h | 9 ++++----- 6 files changed, 71 insertions(+), 56 deletions(-) (limited to 'src') 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 #include +#include // With Borland C++ 5.5, including 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 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 #include +#include + #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 #include +#include + #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 +#include + #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 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; -- cgit v1.2.3