diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e0eda7b1..1fd49e2d 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3642,8 +3642,11 @@ void Notepad_plus::command(int id) const int strSize = FINDREPLACE_MAXLENGTH; TCHAR text2Find[strSize]; - _pEditView->getGenericSelectedText(text2Find, strSize); - + _pEditView->getGenericSelectedText(text2Find, strSize, false); + if (text2Find[0] == '\0') + { + _pEditView->getGenericWordOnCaretPos(text2Find, strSize); + } _findReplaceDlg.markAll(text2Find, styleID); break; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 0fe83664..ec01590d 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1630,6 +1630,50 @@ void ScintillaEditView::replaceSelWith(const char * replaceText) execute(SCI_REPLACESEL, 0, (WPARAM)replaceText); } +char * ScintillaEditView::getWordFromRange(char * txt, int size, int pos1, int pos2) +{ + if (!size) + return NULL; + if (pos1 > pos2) + { + int tmp = pos1; + pos1 = pos2; + pos2 = tmp; + } + + if (size < pos2-pos1) + return NULL; + + getText(txt, pos1, pos2); + return txt; +} + +char * ScintillaEditView::getWordOnCaretPos(char * txt, int size) +{ + if (!size) + return NULL; + + pair range = getWordRange(); + return getWordFromRange(txt, size, range.first, range.second); +} + +TCHAR * ScintillaEditView::getGenericWordOnCaretPos(TCHAR * txt, int size) +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + char *txtA = new char[size + 1]; + getWordOnCaretPos(txtA, size); + + const TCHAR * txtW = wmc->char2wchar(txtA, cp); + lstrcpy(txt, txtW); + delete [] txtA; + return txt; +#else + return getWordOnCaretPos(txt, size); +#endif +} + char * ScintillaEditView::getSelectedText(char * txt, int size, bool expand) { if (!size) @@ -1644,8 +1688,8 @@ char * ScintillaEditView::getSelectedText(char * txt, int size, bool expand) { range.cpMax = range.cpMin+size-1; //keep room for zero terminator } - getText(txt, range.cpMin, range.cpMax); - return txt; + //getText(txt, range.cpMin, range.cpMax); + return getWordFromRange(txt, size, range.cpMin, range.cpMax); } TCHAR * ScintillaEditView::getGenericSelectedText(TCHAR * txt, int size, bool expand) @@ -2250,14 +2294,21 @@ void ScintillaEditView::convertSelectedTextTo(bool Case) } -bool ScintillaEditView::expandWordSelection() + +pair ScintillaEditView::getWordRange() { - int caretPos = execute(SCI_GETCURRENTPOS, 0, 0); + int caretPos = execute(SCI_GETCURRENTPOS, 0, 0); int startPos = static_cast(execute(SCI_WORDSTARTPOSITION, caretPos, true)); int endPos = static_cast(execute(SCI_WORDENDPOSITION, caretPos, true)); - if (startPos != endPos) { - execute(SCI_SETSELECTIONSTART, startPos); - execute(SCI_SETSELECTIONEND, endPos); + return pair(startPos, endPos); +} + +bool ScintillaEditView::expandWordSelection() +{ + pair wordRange = getWordRange(); + if (wordRange.first != wordRange.second) { + execute(SCI_SETSELECTIONSTART, wordRange.first); + execute(SCI_SETSELECTIONEND, wordRange.second); return true; } return false; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index a25be218..9009ce36 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -240,7 +240,10 @@ public: return (range.cpMax - range.cpMin); }; + char * getWordFromRange(char * txt, int size, int pos1, int pos2); char * getSelectedText(char * txt, int size, bool expand = true); + char * getWordOnCaretPos(char * txt, int size); + TCHAR * getGenericWordOnCaretPos(TCHAR * txt, int size); TCHAR * getGenericSelectedText(TCHAR * txt, int size, bool expand = true); int searchInTarget(const TCHAR * Text2Find, int fromPos, int toPos) const; void appandGenericText(const TCHAR * text2Append) const; @@ -850,6 +853,7 @@ protected: }; void setTabSettings(Lang *lang); + pair getWordRange(); bool expandWordSelection(); };