From 07510a6ffd4f5b286c0d39711ddd9a651c4a84e2 Mon Sep 17 00:00:00 2001
From: Neil
Date: Tue, 17 Dec 2013 14:16:29 +1100
Subject: Added DropSelectionN API.
---
doc/ScintillaDoc.html | 7 +++++++
doc/ScintillaHistory.html | 3 +++
include/Scintilla.h | 1 +
include/Scintilla.iface | 3 +++
src/Editor.cxx | 5 +++++
src/Selection.cxx | 15 +++++++++++++++
src/Selection.h | 1 +
test/simpleTests.py | 34 ++++++++++++++++++++++++++++++++++
8 files changed, 69 insertions(+)
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 43ec2d526..3be837849 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -1565,6 +1565,7 @@ struct Sci_TextToFind {
SCI_CLEARSELECTIONS
SCI_SETSELECTION(int caret, int anchor)
SCI_ADDSELECTION(int caret, int anchor)
+ SCI_DROPSELECTIONN(int selection)
SCI_SETMAINSELECTION(int selection)
SCI_GETMAINSELECTION
@@ -1691,6 +1692,12 @@ struct Sci_TextToFind {
Since there is always at least one selection, to set a list of selections, the first selection should be
added with SCI_SETSELECTION and later selections added with SCI_ADDSELECTION
+
+ SCI_DROPSELECTIONN(int selection)
+ If there are multiple selections, remove the indicated selection.
+ If this was the main selection then make the previous selection the main and if it was the first then the last selection becomes main.
+ If there is only one selection, or there is no selection selection, then there is no effect.
+
SCI_SETMAINSELECTION(int selection)
SCI_GETMAINSELECTION
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 7b377d640..9418f6605 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -458,6 +458,9 @@
Released 12 December 2013.
+ Added DropSelectionN API to drop a selection from a multiple selection.
+
+
C++ lexer fixes bug where keyword followed immediately by quoted string continued
keyword style.
Bug #1564.
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 77d1097a0..39171bad4 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -817,6 +817,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_CLEARSELECTIONS 2571
#define SCI_SETSELECTION 2572
#define SCI_ADDSELECTION 2573
+#define SCI_DROPSELECTIONN 2671
#define SCI_SETMAINSELECTION 2574
#define SCI_GETMAINSELECTION 2575
#define SCI_SETSELECTIONNCARET 2576
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 01c3f82e7..7b38eb852 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2176,6 +2176,9 @@ fun int SetSelection=2572(int caret, int anchor)
# Add a selection
fun int AddSelection=2573(int caret, int anchor)
+# Drop one selection
+fun void DropSelectionN=2671(int selection,)
+
# Set the main selection
set void SetMainSelection=2574(int selection,)
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 7e1da9e20..f254af4dd 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -9526,6 +9526,11 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
Redraw();
break;
+ case SCI_DROPSELECTIONN:
+ sel.DropSelection(wParam);
+ Redraw();
+ break;
+
case SCI_SETMAINSELECTION:
sel.SetMain(wParam);
Redraw();
diff --git a/src/Selection.cxx b/src/Selection.cxx
index 0c02c198b..ae4d8bfc7 100644
--- a/src/Selection.cxx
+++ b/src/Selection.cxx
@@ -305,6 +305,21 @@ void Selection::AddSelectionWithoutTrim(SelectionRange range) {
mainRange = ranges.size() - 1;
}
+void Selection::DropSelection(size_t r) {
+ if ((ranges.size() > 1) && (r < ranges.size())) {
+ size_t mainNew = mainRange;
+ if (mainNew >= r) {
+ if (mainNew == 0) {
+ mainNew = ranges.size() - 2;
+ } else {
+ mainNew--;
+ }
+ }
+ ranges.erase(ranges.begin() + r);
+ mainRange = mainNew;
+ }
+}
+
void Selection::TentativeSelection(SelectionRange range) {
if (!tentativeMain) {
rangesSaved = ranges;
diff --git a/src/Selection.h b/src/Selection.h
index 956a0f99d..e84d3c32c 100644
--- a/src/Selection.h
+++ b/src/Selection.h
@@ -167,6 +167,7 @@ public:
void SetSelection(SelectionRange range);
void AddSelection(SelectionRange range);
void AddSelectionWithoutTrim(SelectionRange range);
+ void DropSelection(size_t r);
void TentativeSelection(SelectionRange range);
void CommitTentative();
int CharacterInSelection(int posCharacter) const;
diff --git a/test/simpleTests.py b/test/simpleTests.py
index 03deb566d..bf8a4f786 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -1382,6 +1382,40 @@ class TestMultiSelection(unittest.TestCase):
self.assertEquals(self.ed.GetSelectionNAnchorVirtualSpace(0), 0)
self.assertEquals(self.ed.GetSelectionNCaret(0), 3)
self.assertEquals(self.ed.GetSelectionNCaretVirtualSpace(0), 0)
+
+ def testDropSelectionN(self):
+ self.ed.SetSelection(1, 2)
+ # Only one so dropping has no effect
+ self.ed.DropSelectionN(0)
+ self.assertEquals(self.ed.Selections, 1)
+ self.ed.AddSelection(4, 5)
+ self.assertEquals(self.ed.Selections, 2)
+ # Outside bounds so no effect
+ self.ed.DropSelectionN(2)
+ self.assertEquals(self.ed.Selections, 2)
+ # Dropping before main so main decreases
+ self.ed.DropSelectionN(0)
+ self.assertEquals(self.ed.Selections, 1)
+ self.assertEquals(self.ed.MainSelection, 0)
+ self.assertEquals(self.ed.GetSelectionNCaret(0), 4)
+ self.assertEquals(self.ed.GetSelectionNAnchor(0), 5)
+
+ self.ed.AddSelection(10, 11)
+ self.ed.AddSelection(20, 21)
+ self.assertEquals(self.ed.Selections, 3)
+ self.assertEquals(self.ed.MainSelection, 2)
+ self.ed.MainSelection = 1
+ # Dropping after main so main does not change
+ self.ed.DropSelectionN(2)
+ self.assertEquals(self.ed.MainSelection, 1)
+
+ # Dropping first selection so wraps around to new last.
+ self.ed.AddSelection(30, 31)
+ self.ed.AddSelection(40, 41)
+ self.assertEquals(self.ed.Selections, 4)
+ self.ed.MainSelection = 0
+ self.ed.DropSelectionN(0)
+ self.assertEquals(self.ed.MainSelection, 2)
class TestCharacterNavigation(unittest.TestCase):
def setUp(self):
--
cgit v1.2.3