aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaDoc.html10
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface8
-rw-r--r--src/Document.cxx39
-rw-r--r--src/Editor.cxx6
5 files changed, 41 insertions, 24 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index a7970d614..66944ec97 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -885,6 +885,8 @@ struct TextToFind {
onlyWordCharacters)</a><br />
<a class="message" href="#SCI_WORDSTARTPOSITION">SCI_WORDSTARTPOSITION(int position, bool
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_TEXTWIDTH">SCI_TEXTWIDTH(int styleNumber, char *text)</a><br />
<a class="message" href="#SCI_TEXTHEIGHT">SCI_TEXTHEIGHT(int line)</a><br />
<a class="message" href="#SCI_CHOOSECARETX">SCI_CHOOSECARETX</a><br />
@@ -1149,6 +1151,14 @@ struct TextToFind {
</tbody>
</table>
+ <p><b id="SCI_POSITIONBEFORE">SCI_POSITIONBEFORE(int position)</b><br />
+ <b id="SCI_POSITIONAFTER">SCI_POSITIONAFTER(int position)</b><br />
+ These messages return the position before and after another position
+ in the document taking into account the current code page. The minimum
+ position returned is 0 and the maximum is the last position in the document.
+ 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_TEXTWIDTH">SCI_TEXTWIDTH(int styleNumber, char *text)</b><br />
This returns the pixel width of a string drawn in the given <code>styleNumber</code> which can
be used, for example, to decide how wide to make the line number margin in order to display a
diff --git a/include/Scintilla.h b/include/Scintilla.h
index c377d07cc..470425e76 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -535,6 +535,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_PARADOWNEXTEND 2414
#define SCI_PARAUP 2415
#define SCI_PARAUPEXTEND 2416
+#define SCI_POSITIONBEFORE 2417
+#define SCI_POSITIONAFTER 2418
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
#define SCI_SETLEXER 4001
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 8ad828cd0..3b71a37a3 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1441,6 +1441,14 @@ fun void ParaDownExtend=2414(,)
fun void ParaUp=2415(,)
fun void ParaUpExtend=2416(,)
+# Given a valid document position, return the previous position taking code
+# page into account. Returns 0 if passed 0.
+fun position PositionBefore=2417(position pos,)
+
+# Given a valid document position, return the next position taking code
+# page into account. Maximum value returned is the last position in the document.
+fun position PositionAfter=2418(position pos,)
+
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
diff --git a/src/Document.cxx b/src/Document.cxx
index 255c9ee11..98fc6b330 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -265,7 +265,7 @@ int Document::LenChar(int pos) {
return 1;
}
}
-
+#include <assert.h>
// Normalise a position so that it is not halfway through a two byte character.
// This can occur in two situations -
// When lines are terminated with \r\n pairs which should be treated as one character.
@@ -273,17 +273,11 @@ int Document::LenChar(int pos) {
// If moving, move the position in the indicated direction.
int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {
//Platform::DebugPrintf("NoCRLF %d %d\n", pos, moveDir);
- // If out of range, just return value - should be fixed up after
- if (pos < 0)
- return pos;
- if (pos > Length())
- return pos;
-
- // Position 0 and Length() can not be between any two characters
- if (pos == 0)
- return pos;
- if (pos == Length())
- return pos;
+ // If out of range, just return minimum/maximum value.
+ if (pos <= 0)
+ return 0;
+ if (pos >= Length())
+ return Length();
// assert pos > 0 && pos < Length()
if (checkLineEnd && IsCrLf(pos - 1)) {
@@ -309,29 +303,26 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {
} else {
// Anchor DBCS calculations at start of line because start of line can
// not be a DBCS trail byte.
- int startLine = pos;
-
- while (startLine > 0 && cb.CharAt(startLine) != '\r' && cb.CharAt(startLine) != '\n')
- startLine--;
- while (startLine < pos) {
+ int posCheck = LineStart(LineFromPosition(pos));
+ while (posCheck < pos) {
char mbstr[maxBytesInDBCSCharacter+1];
int i;
for(i=0;i<Platform::DBCSCharMaxLength();i++) {
- mbstr[i] = cb.CharAt(startLine+i);
+ mbstr[i] = cb.CharAt(posCheck+i);
}
mbstr[i] = '\0';
int mbsize = Platform::DBCSCharLength(dbcsCodePage, mbstr);
- if (startLine + mbsize == pos) {
+ if (posCheck + mbsize == pos) {
return pos;
- } else if (startLine + mbsize > pos) {
+ } else if (posCheck + mbsize > pos) {
if (moveDir > 0) {
- return startLine + mbsize;
+ return posCheck + mbsize;
} else {
- return startLine;
+ return posCheck;
}
}
- startLine += mbsize;
+ posCheck += mbsize;
}
}
}
@@ -938,7 +929,7 @@ long Document::FindText(int minPos, int maxPos, const char *s,
endOfLine = startPos;
}
}
-
+
DocumentIndexer di(this, endOfLine);
int success = pre->Execute(di, startOfLine, endOfLine);
if (success) {
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 44399a5fb..2eba8a471 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5199,6 +5199,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETSEARCHFLAGS:
return searchFlags;
+ case SCI_POSITIONBEFORE:
+ return pdoc->MovePositionOutsideChar(wParam-1, -1, true);
+
+ case SCI_POSITIONAFTER:
+ return pdoc->MovePositionOutsideChar(wParam+1, 1, true);
+
case SCI_LINESCROLL:
ScrollTo(topLine + lParam);
HorizontalScrollTo(xOffset + wParam * vs.spaceWidth);