Skip to content

Commit 5c6f89d

Browse files
alankilborndonho
authored andcommitted
Add capacity of pasting multiline into Find/Replace fields
Fix notepad-plus-plus#16952, close notepad-plus-plus#16956
1 parent de7aa5a commit 5c6f89d

3 files changed

Lines changed: 71 additions & 4 deletions

File tree

PowerEditor/src/MISC/Common/Common.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,29 @@ bool str2Clipboard(const wstring &str2cpy, HWND hwnd)
955955
return true;
956956
}
957957

958+
std::wstring strFromClipboard()
959+
{
960+
std::wstring clipboardText;
961+
if (::OpenClipboard(NULL))
962+
{
963+
if (::IsClipboardFormatAvailable(CF_UNICODETEXT))
964+
{
965+
HANDLE hClipboardData = ::GetClipboardData(CF_UNICODETEXT);
966+
if (hClipboardData)
967+
{
968+
wchar_t* pWc = static_cast<wchar_t*>(::GlobalLock(hClipboardData));
969+
if (pWc)
970+
{
971+
clipboardText = pWc;
972+
::GlobalUnlock(hClipboardData);
973+
}
974+
}
975+
}
976+
::CloseClipboard();
977+
}
978+
return clipboardText;
979+
}
980+
958981
bool buf2Clipboard(const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd)
959982
{
960983
const wstring crlf = L"\r\n";

PowerEditor/src/MISC/Common/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ std::wstring stringTakeWhileAdmissable(const std::wstring& input, const std::wst
169169
double stodLocale(const std::wstring& str, _locale_t loc, size_t* idx = NULL);
170170

171171
bool str2Clipboard(const std::wstring &str2cpy, HWND hwnd);
172+
std::wstring strFromClipboard();
172173
class Buffer;
173174
bool buf2Clipboard(const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd);
174175

PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ wstring getTextFromCombo(HWND hCombo)
5353
auto str = std::make_unique<wchar_t[]>(strSize);
5454
std::fill_n(str.get(), strSize, L'\0');
5555

56-
::SendMessage(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast<LPARAM>(str.get()));
56+
::SendMessage(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH, reinterpret_cast<LPARAM>(str.get()));
5757
return wstring(str.get());
5858
}
5959

@@ -63,7 +63,7 @@ void delLeftWordInEdit(HWND hEdit)
6363
auto str = std::make_unique<wchar_t[]>(strSize);
6464
std::fill_n(str.get(), strSize, L'\0');
6565

66-
::SendMessage(hEdit, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast<LPARAM>(str.get()));
66+
::SendMessage(hEdit, WM_GETTEXT, FINDREPLACE_MAXLENGTH, reinterpret_cast<LPARAM>(str.get()));
6767
WORD cursor = 0;
6868
::SendMessage(hEdit, EM_GETSEL, (WPARAM)&cursor, 0);
6969
WORD wordstart = cursor;
@@ -4919,7 +4919,7 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM
49194919
else if ((message == WM_KEYDOWN) && (wParam == VK_DOWN) && (::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0) == CB_ERR))
49204920
{
49214921
// down key on unselected combobox item -> store current edit text as draft
4922-
::SendMessage(hwndCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast<LPARAM>(draftString.get()));
4922+
::SendMessage(hwndCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH, reinterpret_cast<LPARAM>(draftString.get()));
49234923
}
49244924
else if ((message == WM_KEYDOWN) && (wParam == VK_UP) && (::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0) == CB_ERR))
49254925
{
@@ -4931,11 +4931,54 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM
49314931
{
49324932
// up key on top selected combobox item -> restore draft to edit text
49334933
::SendMessage(hwndCombo, CB_SETCURSEL, WPARAM(-1), 0);
4934-
::SendMessage(hwndCombo, WM_SETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast<LPARAM>(draftString.get()));
4934+
::SendMessage(hwndCombo, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(draftString.get()));
49354935
::SendMessage(hwndCombo, CB_SETEDITSEL, 0, MAKELPARAM(0, -1));
49364936
return 0;
49374937

49384938
}
4939+
else if (message == WM_PASTE)
4940+
{
4941+
// needed to allow CR (i.e., multiline) into combobox text;
4942+
// (the default functionality terminates the paste at the first CR character)
4943+
4944+
HWND hParent = ::GetParent(hwndCombo);
4945+
HWND hFindWhatCombo = ::GetDlgItem(hParent, IDFINDWHAT);
4946+
HWND hReplaceWithCombo = ::GetDlgItem(hParent, IDREPLACEWITH);
4947+
if ((hwndCombo == hFindWhatCombo) || (hwndCombo == hReplaceWithCombo))
4948+
{
4949+
CLIPFORMAT cfColumnSelect = static_cast<CLIPFORMAT>(::RegisterClipboardFormat(L"MSDEVColumnSelect"));
4950+
if (!::IsClipboardFormatAvailable(cfColumnSelect))
4951+
{
4952+
wstring clipboardText = strFromClipboard();
4953+
if (!clipboardText.empty())
4954+
{
4955+
wstring origText = getTextFromCombo(hwndCombo);
4956+
4957+
DWORD selStartIndex = 0;
4958+
DWORD selEndIndex = 0;
4959+
// In case there are selected text in combo box field
4960+
::SendMessage(hwndCombo, CB_GETEDITSEL, (WPARAM)&selStartIndex, (LPARAM)&selEndIndex);
4961+
4962+
wstring changedText = origText.substr(0, selStartIndex) + clipboardText + origText.substr(selEndIndex);
4963+
if (changedText.length() > FINDREPLACE_MAXLENGTH - 1)
4964+
{
4965+
changedText = changedText.substr(0, FINDREPLACE_MAXLENGTH - 1);
4966+
}
4967+
4968+
if (changedText != origText)
4969+
{
4970+
::SendMessage(hwndCombo, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(changedText.c_str()));
4971+
4972+
::SendMessage(hParent, WM_COMMAND,
4973+
MAKELPARAM(hwndCombo == hFindWhatCombo ? IDFINDWHAT : IDREPLACEWITH, CBN_EDITUPDATE),
4974+
reinterpret_cast<LPARAM>(hwndCombo));
4975+
}
4976+
}
4977+
}
4978+
4979+
return 0;
4980+
}
4981+
}
49394982
return CallWindowProc(originalComboEditProc, hwnd, message, wParam, lParam);
49404983
}
49414984

0 commit comments

Comments
 (0)