diff options
author | nyamatongwe <devnull@localhost> | 2000-09-04 13:12:01 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2000-09-04 13:12:01 +0000 |
commit | e8bed10157d033945af86565909b71c628f822b2 (patch) | |
tree | 105694b92861b678ee50da068da5501fb33758ae /src | |
parent | 7b21a9fc9281af3b17bb05b699e2a74f089b4812 (diff) | |
download | scintilla-mirror-e8bed10157d033945af86565909b71c628f822b2.tar.gz |
Added SCFIND_WORDSTART.
Diffstat (limited to 'src')
-rw-r--r-- | src/Document.cxx | 38 | ||||
-rw-r--r-- | src/Document.h | 5 | ||||
-rw-r--r-- | src/Editor.cxx | 16 |
3 files changed, 36 insertions, 23 deletions
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) { |