From 3b031e3e5ec28064ce2bb4e67e0d9e48a40ee594 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 18 Apr 2003 10:19:52 +0000 Subject: New methods for finding the next or previous position taking multi byte characters into account. --- doc/ScintillaDoc.html | 10 ++++++++++ include/Scintilla.h | 2 ++ include/Scintilla.iface | 8 ++++++++ src/Document.cxx | 39 +++++++++++++++------------------------ src/Editor.cxx | 6 ++++++ 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)
SCI_WORDSTARTPOSITION(int position, bool onlyWordCharacters)
+ SCI_POSITIONBEFORE(int position)
+ SCI_POSITIONAFTER(int position)
SCI_TEXTWIDTH(int styleNumber, char *text)
SCI_TEXTHEIGHT(int line)
SCI_CHOOSECARETX
@@ -1149,6 +1151,14 @@ struct TextToFind { +

SCI_POSITIONBEFORE(int position)
+ SCI_POSITIONAFTER(int position)
+ 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.

+

SCI_TEXTWIDTH(int styleNumber, char *text)
This returns the pixel width of a string drawn in the given styleNumber 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 // 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 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); -- cgit v1.2.3