diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 6bea257e6..eb6a1240f 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1443,8 +1443,8 @@ void Notepad_plus::command(int id) if (isFirstTime) _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL(), false); - const wchar_t* str = _findReplaceDlg.setSearchTextWithSettings(); - if (!str) return; + wstring str = _findReplaceDlg.setSearchText(); + if (str.empty()) return; _findReplaceDlg._env->_str2Search = str; @@ -1457,7 +1457,7 @@ void Notepad_plus::command(int id) op._whichDirection = (id == IDM_SEARCH_SETANDFINDNEXT?DIR_DOWN:DIR_UP); FindStatus status = FSNoMessage; - _findReplaceDlg.processFindNext(str, &op, &status); + _findReplaceDlg.processFindNext(str.c_str(), &op, &status); if (status == FSEndReached) { wstring msg = _nativeLangSpeaker.getLocalizedStrFromID("find-status-end-reached", FIND_STATUS_END_REACHED_TEXT); diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index beaa144af..b788eae7d 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -5375,10 +5375,27 @@ bool FindReplaceDlg::replaceInOpenDocsConfirmCheck() return confirmed; } -// return NULL if nothing to set in find field. -// Otherwise return string pointer (wchar_t *) in which the selected text was copied. -// Note that the string pointer don't need to and should not be deallocated. -const wchar_t* FindReplaceDlg::setSearchTextWithSettings() +// Expand selection (if needed) and set the selected text in Find What field. +// Return empty string if nothing to set in find field. +// Otherwise return string in which the selected text was copied. +wstring FindReplaceDlg::setSearchText() +{ + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + Sci_Position selStrCharNum = 0; + const wchar_t* selStr = (*_ppEditView)->getSelectedTextToWChar(true, &selStrCharNum); + + if (selStr && selStrCharNum <= nppGui._fillFindWhatThreshold) + { + setSearchText(selStr); + return selStr; + } + return L""; +} + +// Set the selected text in Find What field, according the Search settings. +// Return empty string if nothing to set in find field. +// Otherwise return string in which the selected text was copied. +wstring FindReplaceDlg::setSearchTextWithSettings() { const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); if (nppGui._fillFindFieldWithSelected) @@ -5392,7 +5409,7 @@ const wchar_t* FindReplaceDlg::setSearchTextWithSettings() return selStr; } } - return nullptr; + return L""; } wstring Finder::getHitsString(int count) const diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h index f6115771b..acd16f193 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h @@ -419,7 +419,8 @@ public : DIALOG_TYPE getCurrentStatus() { return _currentStatus; } Finder* getFinderFrom(HWND hwnd); int regexBackwardMsgBox(); - const wchar_t* setSearchTextWithSettings(); + std::wstring setSearchText(); + std::wstring setSearchTextWithSettings(); protected : void resizeDialogElements();