From 037b41e29ae30febefe73c7f61a3065d9c6ffcd9 Mon Sep 17 00:00:00 2001 From: Cyrillev91 Date: Fri, 12 Jun 2015 19:39:41 +0200 Subject: [PATCH] Fix smart highlighting not working in some case. Change isQualifiedWord because isQualifiedWord use hardcode and no SCI_GETWORDCHARS smarthighlight is not always OK. This Fix use SCI_GETWORDCHARS. (closes #187) --- .../ScitillaComponent/SmartHighlighter.cpp | 65 ++++++------------- .../src/ScitillaComponent/SmartHighlighter.h | 4 +- 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp index 3fa21f67a..8a377634e 100644 --- a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp @@ -56,27 +56,34 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) char * text2Find = new char[textlen]; pHighlightView->getSelectedText(text2Find, textlen, false); //do not expand selection (false) + + //GETWORDCHARS for isQualifiedWord2() and isWordChar2() + int listCharSize = pHighlightView->execute(SCI_GETWORDCHARS, 0, 0); + char *listChar = new char[listCharSize+1]; + pHighlightView->execute(SCI_GETWORDCHARS, 0, (LPARAM)listChar); + bool valid = true; //The word has to consist if wordChars only, and the characters before and after something else - if (!isQualifiedWord(text2Find)) + if (!isQualifiedWord(text2Find, listChar)) valid = false; else { UCHAR c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMax); if (c) { - if (isWordChar(char(c))) + if (isWordChar(char(c), listChar)) valid = false; } c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMin-1); if (c) { - if (isWordChar(char(c))) + if (isWordChar(char(c), listChar)) valid = false; } } if (!valid) { delete [] text2Find; + delete [] listChar; return; } @@ -126,60 +133,28 @@ void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) // restore the original targets to avoid conflicts with the search/replace functions pHighlightView->execute(SCI_SETTARGETSTART, originalStartPos); pHighlightView->execute(SCI_SETTARGETEND, originalEndPos); + delete [] listChar; } -bool SmartHighlighter::isQualifiedWord(const char *str) const +bool SmartHighlighter::isQualifiedWord(const char *str, char *listChar) const { for (size_t i = 0, len = strlen(str) ; i < len ; ++i) { - if (!isWordChar(str[i])) + if (!isWordChar(str[i], listChar)) return false; } return true; }; -bool SmartHighlighter::isWordChar(char ch) const +bool SmartHighlighter::isWordChar(char ch, char listChar[]) const { - if ((UCHAR)ch < 0x20) - return false; - switch(ch) + for (size_t i = 0, len = strlen(listChar) ; i < len ; ++i) { - case ' ': - case ' ': - case '\n': - case '\r': - case '.': - case ',': - case '?': - case ';': - case ':': - case '!': - case '(': - case ')': - case '[': - case ']': - case '+': - case '-': - case '*': - case '/': - case '#': - case '@': - case '^': - case '%': - case '$': - case '"': - case '\'': - case '~': - case '&': - case '{': - case '}': - case '|': - case '=': - case '<': - case '>': - case '\\': - return false; + if (ch == listChar[i]) + { + return true; + } } - return true; + return false; }; diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.h b/PowerEditor/src/ScitillaComponent/SmartHighlighter.h index f76c9bb39..01b30a7d7 100644 --- a/PowerEditor/src/ScitillaComponent/SmartHighlighter.h +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.h @@ -38,8 +38,8 @@ public: private: FindReplaceDlg * _pFRDlg; - bool isQualifiedWord(const char *str) const; - bool isWordChar(char ch) const; + bool isQualifiedWord(const char *str, char listChar[]) const; + bool isWordChar(char ch, char listChar[]) const; }; #endif //SMARTHIGHLIGHTER_H \ No newline at end of file