From 130731d7c7bb43e82d5b1d9eb1441b1e07124b05 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 15 Jul 2009 03:05:04 +0000 Subject: No explicit count of ranges in selection as can use vector::size(). Removed EmptyRanges method so that there is always at least one selection. Added SetSelection method to set a simple single selection. Removed 3 argument form of AddSelection since callers do know which argument is the caret. Simplified rectangular selection code. --- src/Selection.cxx | 79 +++++++++++++++++-------------------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) (limited to 'src/Selection.cxx') diff --git a/src/Selection.cxx b/src/Selection.cxx index eada57d5e..43607b244 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -72,26 +72,6 @@ int SelectionRange::Length() const { } } -#ifdef NEEDED -// Like Length but takes virtual space into account -int SelectionRange::Width() const { - SelectionPosition first; - SelectionPosition last; - if (anchor > caret) { - first = caret; - last = anchor; - } else { - first = anchor; - last = caret; - } - if (first.Position() == last.Position()) { - return last.VirtualSpace() - first.VirtualSpace(); - } else { - return last.Position() - first.Position() + last.VirtualSpace(); - } -} -#endif - bool SelectionRange::Contains(int pos) const { if (anchor > caret) return (pos >= caret.Position()) && (pos <= anchor.Position()); @@ -176,7 +156,7 @@ void SelectionRange::MinimizeVirtualSpace() { } } -Selection::Selection() : ranges(0), nRanges(0), mainRange(0), moveExtends(false), selType(selStream) { +Selection::Selection() : mainRange(0), moveExtends(false), selType(selStream) { AddSelection(SelectionPosition(0)); } @@ -200,7 +180,7 @@ SelectionRange &Selection::Rectangular() { } size_t Selection::Count() const { - return nRanges; + return ranges.size(); } size_t Selection::Main() const { @@ -208,7 +188,7 @@ size_t Selection::Main() const { } void Selection::SetMain(size_t r) { - PLATFORM_ASSERT(r < nRanges); + PLATFORM_ASSERT(r < ranges.size()); mainRange = r; } @@ -220,10 +200,6 @@ SelectionRange &Selection::RangeMain() { return ranges[mainRange]; } -void Selection::ClearVirtualSpace(size_t r) { - ranges[r].ClearVirtualSpace(); -} - bool Selection::MoveExtends() const { return moveExtends; } @@ -233,7 +209,7 @@ void Selection::SetMoveExtends(bool moveExtends_) { } bool Selection::Empty() const { - for (size_t i=0; i ranges[i].Start().Position()) && (pos <= ranges[i].End().Position())) return i == mainRange ? 1 : 2; } @@ -319,7 +292,7 @@ int Selection::InSelectionForEOL(int pos) const { int Selection::VirtualSpaceFor(int pos) const { int virtualSpace = 0; - for (size_t i=0; i