aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2013-08-20 14:57:56 +1000
committerNeil <nyamatongwe@gmail.com>2013-08-20 14:57:56 +1000
commit70acfa623be189df50b42a7402085e782341fec2 (patch)
tree609f95d4dc215476e240d62bf4ef5b0a12ec0fe4
parente88c427ffcf8731edf9dc0957c28c3e0ec78bda5 (diff)
downloadscintilla-mirror-70acfa623be189df50b42a7402085e782341fec2.tar.gz
Added PositionRelative to optimize navigation by character.
-rw-r--r--doc/ScintillaDoc.html6
-rw-r--r--doc/ScintillaHistory.html3
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface4
-rw-r--r--src/Editor.cxx3
-rw-r--r--test/simpleTests.py45
6 files changed, 62 insertions, 0 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 57550bfe6..cca207dae 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -1161,6 +1161,7 @@ struct Sci_TextToFind {
onlyWordCharacters)</a><br />
<a class="message" href="#SCI_POSITIONBEFORE">SCI_POSITIONBEFORE(int position)</a><br />
<a class="message" href="#SCI_POSITIONAFTER">SCI_POSITIONAFTER(int position)</a><br />
+ <a class="message" href="#SCI_POSITIONRELATIVE">SCI_POSITIONRELATIVE(int position, int relative)</a><br />
<a class="message" href="#SCI_COUNTCHARACTERS">SCI_COUNTCHARACTERS(int startPos, int endPos)</a><br />
<a class="message" href="#SCI_TEXTWIDTH">SCI_TEXTWIDTH(int styleNumber, const char *text)</a><br />
<a class="message" href="#SCI_TEXTHEIGHT">SCI_TEXTHEIGHT(int line)</a><br />
@@ -1466,6 +1467,11 @@ struct Sci_TextToFind {
If called with a position within a multi byte character will return the position
of the start/end of that character.</p>
+ <p><b id="SCI_POSITIONRELATIVE">SCI_POSITIONRELATIVE(int position, int relative)</b><br />
+ Count a number of whole characters before or after the argument position and return that position.
+ The minimum position returned is 0 and the maximum is the last position in the document.
+ </p>
+
<p><b id="SCI_COUNTCHARACTERS">SCI_COUNTCHARACTERS(int startPos, int endPos)</b><br />
Returns the number of whole characters between two positions..</p>
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index e0ccc5966..97ff11f58 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -452,6 +452,9 @@
In Unicode mode C1 control characters are represented by their mnemonics.
</li>
<li>
+ Added SCI_POSITIONRELATIVE to optimize navigation by character.
+ </li>
+ <li>
Option to allow mouse selection to switch to rectangular by pressing Alt after start of gesture.
<a href="http://sourceforge.net/p/scintilla/feature-requests/1007/">Feature #1007.</a>
</li>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 5bfcfc266..405cc81f7 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -673,6 +673,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_PARAUPEXTEND 2416
#define SCI_POSITIONBEFORE 2417
#define SCI_POSITIONAFTER 2418
+#define SCI_POSITIONRELATIVE 2670
#define SCI_COPYRANGE 2419
#define SCI_COPYTEXT 2420
#define SC_SEL_STREAM 0
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index f7880a035..7909f2084 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1756,6 +1756,10 @@ fun position PositionBefore=2417(position pos,)
# page into account. Maximum value returned is the last position in the document.
fun position PositionAfter=2418(position pos,)
+# Given a valid document position, return a position that differs in a number
+# of characters. Returned value is always between 0 and last position in document.
+fun position PositionRelative=2670(position pos, int relative)
+
# Copy a range of text to the clipboard. Positions are clipped into the document.
fun void CopyRange=2419(position start, position end)
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 7fa1326a7..afc2983ed 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -7605,6 +7605,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_POSITIONAFTER:
return pdoc->MovePositionOutsideChar(wParam + 1, 1, true);
+ case SCI_POSITIONRELATIVE:
+ return Platform::Clamp(pdoc->GetRelativePosition(wParam, lParam), 0, pdoc->Length());
+
case SCI_LINESCROLL:
ScrollTo(topLine + lParam);
HorizontalScrollTo(xOffset + static_cast<int>(wParam) * vs.spaceWidth);
diff --git a/test/simpleTests.py b/test/simpleTests.py
index 57607c375..30e74209d 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -1376,6 +1376,51 @@ class TestMultiSelection(unittest.TestCase):
self.assertEquals(self.ed.GetSelectionNCaret(0), 3)
self.assertEquals(self.ed.GetSelectionNCaretVirtualSpace(0), 0)
+class TestCharacterNavigation(unittest.TestCase):
+ def setUp(self):
+ self.xite = Xite.xiteFrame
+ self.ed = self.xite.ed
+ self.ed.ClearAll()
+ self.ed.EmptyUndoBuffer()
+ self.ed.SetCodePage(65001)
+
+ def tearDown(self):
+ self.ed.SetCodePage(0)
+
+ def testBeforeAfter(self):
+ t = "aåflﬔ-"
+ tv = t.encode("UTF-8")
+ self.ed.SetContents(tv)
+ pos = 0
+ for i in range(len(t)-1):
+ after = self.ed.PositionAfter(pos)
+ self.assert_(after > i)
+ back = self.ed.PositionBefore(after)
+ self.assertEquals(pos, back)
+ pos = after
+
+ def testRelative(self):
+ # \x61 \xc3\xa5 \xef\xac\x82 \xef\xac\x94 \x2d
+ t = "aåflﬔ-"
+ tv = t.encode("UTF-8")
+ self.ed.SetContents(tv)
+ self.assertEquals(self.ed.PositionRelative(1, 2), 6)
+ self.assertEquals(self.ed.PositionRelative(6, -2), 1)
+ pos = 0
+ previous = 0
+ for i in range(1, len(t)):
+ after = self.ed.PositionRelative(pos, i)
+ self.assert_(after > pos)
+ self.assert_(after > previous)
+ previous = after
+ pos = len(t)
+ previous = pos
+ for i in range(1, len(t)-1):
+ after = self.ed.PositionRelative(pos, -i)
+ self.assert_(after < pos)
+ self.assert_(after < previous)
+ previous = after
+
class TestCaseMapping(unittest.TestCase):
def setUp(self):
self.xite = Xite.xiteFrame