aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2003-04-18 10:19:52 +0000
committernyamatongwe <unknown>2003-04-18 10:19:52 +0000
commit3b031e3e5ec28064ce2bb4e67e0d9e48a40ee594 (patch)
treebe79d641bf1864cfc90539159dff2769ab5541d3 /src
parent9a1ee8d945b1aeeb1dab0d7e7d0710194a5cad5b (diff)
downloadscintilla-mirror-3b031e3e5ec28064ce2bb4e67e0d9e48a40ee594.tar.gz
New methods for finding the next or previous position taking multi byte
characters into account.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx39
-rw-r--r--src/Editor.cxx6
2 files changed, 21 insertions, 24 deletions
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);