diff options
author | nyamatongwe <unknown> | 2000-09-04 13:12:01 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2000-09-04 13:12:01 +0000 |
commit | 90e1b590ae736c53fb37e22ea90c8f07064403e0 (patch) | |
tree | 105694b92861b678ee50da068da5501fb33758ae | |
parent | 4438c10faf264c4b7cff5c29acabe94cce37e32f (diff) | |
download | scintilla-mirror-90e1b590ae736c53fb37e22ea90c8f07064403e0.tar.gz |
Added SCFIND_WORDSTART.
-rw-r--r-- | include/Scintilla.h | 6 | ||||
-rw-r--r-- | include/Scintilla.iface | 7 | ||||
-rw-r--r-- | src/Document.cxx | 38 | ||||
-rw-r--r-- | src/Document.h | 5 | ||||
-rw-r--r-- | src/Editor.cxx | 16 |
5 files changed, 45 insertions, 27 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h index 8497b123a..ca81d135b 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -217,9 +217,11 @@ typedef long (*SciFnDirect)(long ptr, unsigned int iMessage, unsigned long wPara #define SC_PRINT_BLACKONWHITE 2 #define SCI_SETPRINTCOLOURMODE 2148 #define SCI_GETPRINTCOLOURMODE 2149 -#define SCFIND_MATCHCASE 4 -#define SCFIND_WHOLEWORD 2 #define SCFIND_DOWN 1 +#define SCFIND_WHOLEWORD 2 +#define SCFIND_MATCHCASE 4 +#define SCFIND_WORDSTART 0x00100000 +#define SCFIND_REGEXP 0x00200000 #define SCI_FINDTEXT 2150 #define SCI_FORMATRANGE 2151 #define SCI_GETFIRSTVISIBLELINE 2152 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 536ebbd6a..052af92c4 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -557,9 +557,12 @@ set void SetPrintColourMode=2148(int mode,) # Returns the print colour mode. get int GetPrintColourMode=2149(,) -val SCFIND_MATCHCASE=4 -val SCFIND_WHOLEWORD=2 val SCFIND_DOWN=1 +val SCFIND_WHOLEWORD=2 +val SCFIND_MATCHCASE=4 +val SCFIND_WORDSTART=0x00100000 +# SCFIND_REGEXP is not yet implemented. +val SCFIND_REGEXP=0x00200000 # Find some text in the document. fun position FindText=2150(int flags, findtext ft) diff --git a/src/Document.cxx b/src/Document.cxx index f8d349adb..c883dd253 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -717,25 +717,29 @@ int Document::NextWordStart(int pos, int delta) { return pos; } -bool Document::IsWordAt(int start, int end) { - int lengthDoc = Length(); - if (start > 0) { - char ch = CharAt(start - 1); - if (IsWordChar(ch)) - return false; +bool Document::IsWordStartAt(int pos) { + if (pos > 0) { + return !IsWordChar(CharAt(pos - 1)); } - if (end < lengthDoc - 1) { - char ch = CharAt(end); - if (IsWordChar(ch)) - return false; + return true; +} + +bool Document::IsWordEndAt(int pos) { + if (pos < Length() - 1) { + return !IsWordChar(CharAt(pos)); } return true; } +bool Document::IsWordAt(int start, int end) { + return IsWordStartAt(start) && IsWordEndAt(end); +} + // Find text in document, supporting both forward and backward // searches (just pass minPos > maxPos to do a backward search) // Has not been tested with backwards DBCS searches yet. -long Document::FindText(int minPos, int maxPos, const char *s, bool caseSensitive, bool word) { +long Document::FindText(int minPos, int maxPos, const char *s, + bool caseSensitive, bool word, bool wordStart) { bool forward = minPos <= maxPos; int increment = forward ? 1 : -1; @@ -765,8 +769,10 @@ long Document::FindText(int minPos, int maxPos, const char *s, bool caseSensitiv found = false; } if (found) { - if ((!word) || IsWordAt(pos, pos + lengthFind)) - return pos; + if ((!word && !wordStart) || + word && IsWordAt(pos, pos + lengthFind) || + wordStart && IsWordStartAt(pos)) + return pos; } } } else { @@ -778,8 +784,10 @@ long Document::FindText(int minPos, int maxPos, const char *s, bool caseSensitiv found = false; } if (found) { - if ((!word) || IsWordAt(pos, pos + lengthFind)) - return pos; + if (!(word && wordStart) || + word && IsWordAt(pos, pos + lengthFind) || + wordStart && IsWordStartAt(pos)) + return pos; } } } diff --git a/src/Document.h b/src/Document.h index 76f0e101b..af477dd79 100644 --- a/src/Document.h +++ b/src/Document.h @@ -164,7 +164,8 @@ public: int ExtendWordSelect(int pos, int delta); int NextWordStart(int pos, int delta); int Length() { return cb.Length(); } - long FindText(int minPos, int maxPos, const char *s, bool caseSensitive, bool word); + long FindText(int minPos, int maxPos, const char *s, + bool caseSensitive, bool word, bool wordStart); long FindText(int iMessage, unsigned long wParam, long lParam); int LinesTotal(); @@ -190,6 +191,8 @@ public: private: bool IsDBCS(int pos); bool IsWordChar(unsigned char ch); + bool IsWordStartAt(int pos); + bool IsWordEndAt(int pos); bool IsWordAt(int start, int end); void ModifiedAt(int pos); diff --git a/src/Editor.cxx b/src/Editor.cxx index e6f44f5df..487edf9a5 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -934,8 +934,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis rcSegment.top + vsDraw.maxAscent, ctrlChar, strlen(ctrlChar), textBack, textFore); // Manage normal display - } - else { + } else { rcSegment.left = ll.positions[startseg] + xStart; rcSegment.right = ll.positions[i + 1] + xStart; // Only try to draw if really visible - enhances performance by not calling environment to @@ -2305,7 +2304,8 @@ void Editor::Indent(bool forwards) { long Editor::FindText(unsigned int iMessage, unsigned long wParam, long lParam) { TextToFind *ft = reinterpret_cast<TextToFind *>(lParam); int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText, - wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD); + wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART); if (pos != -1) { if (iMessage != EM_FINDTEXT) { ft->chrgText.cpMin = pos; @@ -2337,12 +2337,14 @@ long Editor::SearchText(unsigned int iMessage, unsigned long wParam, long lParam if (iMessage == SCI_SEARCHNEXT) { pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, - wParam & SCFIND_MATCHCASE, - wParam & SCFIND_WHOLEWORD); + wParam & SCFIND_MATCHCASE, + wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART); } else { pos = pdoc->FindText(searchAnchor, 0, txt, - wParam & SCFIND_MATCHCASE, - wParam & SCFIND_WHOLEWORD); + wParam & SCFIND_MATCHCASE, + wParam & SCFIND_WHOLEWORD, + wParam & SCFIND_WORDSTART); } if (pos != -1) { |