aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaDoc.html7
-rw-r--r--doc/ScintillaHistory.html3
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface3
-rw-r--r--src/Editor.cxx5
-rw-r--r--src/Selection.cxx15
-rw-r--r--src/Selection.h1
-rw-r--r--test/simpleTests.py34
8 files changed, 69 insertions, 0 deletions
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 {
<a class="message" href="#SCI_CLEARSELECTIONS">SCI_CLEARSELECTIONS</a><br />
<a class="message" href="#SCI_SETSELECTION">SCI_SETSELECTION(int caret, int anchor)</a><br />
<a class="message" href="#SCI_ADDSELECTION">SCI_ADDSELECTION(int caret, int anchor)</a><br />
+ <a class="message" href="#SCI_DROPSELECTIONN">SCI_DROPSELECTIONN(int selection)</a><br />
<a class="message" href="#SCI_SETMAINSELECTION">SCI_SETMAINSELECTION(int selection)</a><br />
<a class="message" href="#SCI_GETMAINSELECTION">SCI_GETMAINSELECTION</a><br />
<br />
@@ -1692,6 +1693,12 @@ struct Sci_TextToFind {
added with <code>SCI_SETSELECTION</code> and later selections added with <code>SCI_ADDSELECTION</code></p>
<p>
+ <b id="SCI_DROPSELECTIONN">SCI_DROPSELECTIONN(int selection)</b><br />
+ 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 <code>selection</code>, then there is no effect.</p>
+
+ <p>
<b id="SCI_SETMAINSELECTION">SCI_SETMAINSELECTION(int selection)</b><br />
<b id="SCI_GETMAINSELECTION">SCI_GETMAINSELECTION</b><br />
One of the selections is the main selection which is used to determine what range of text is automatically visible.
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.
</li>
<li>
+ Added DropSelectionN API to drop a selection from a multiple selection.
+ </li>
+ <li>
C++ lexer fixes bug where keyword followed immediately by quoted string continued
keyword style.
<a href="http://sourceforge.net/p/scintilla/bugs/1564/">Bug #1564</a>.
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):