Fix Ctrl-C not doing copy from Search result issue

Solution from: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15739#issuecomment-2479671245

Fix #15739, close #15810
This commit is contained in:
Don Ho 2024-11-16 17:52:14 +01:00
parent eeb4753044
commit c24444acfe
15 changed files with 70 additions and 55 deletions

View File

@ -1484,7 +1484,6 @@ Updated to v8.2.1:
<find-result-title-info-selections value="($INT_REPLACE1$ аиқәшәарақәа $INT_REPLACE2$ аҟны иалкаақәоу $INT_REPLACE3$ рҟынтәи)"/> <find-result-title-info-selections value="($INT_REPLACE1$ аиқәшәарақәа $INT_REPLACE2$ аҟны иалкаақәоу $INT_REPLACE3$ рҟынтәи)"/>
<find-result-title-info-extra value=" - Ацәаҳәақәа рФильтр Арежим: иаанарԥшуеит афильтрра алҵшәақәа мацара"/> <find-result-title-info-extra value=" - Ацәаҳәақәа рФильтр Арежим: иаанарԥшуеит афильтрра алҵшәақәа мацара"/>
<find-result-hits value="(Аиқәшәарақәа $INT_REPLACE$)"/> <find-result-hits value="(Аиқәшәарақәа $INT_REPLACE$)"/>
<find-result-hits-and-line-hits value="($INT_REPLACE1$ аиқәшәарақәа ацәаҳәақәа $INT_REPLACE2$ рҟны)"/>
<find-regex-zero-length-match value="ноль аура змоу аиқәшәара"/> <find-regex-zero-length-match value="ноль аура змоу аиқәшәара"/>
<session-save-folder-as-workspace value="Еиқәырхатәуп Акаталог Апроект ҳасабла"/> <session-save-folder-as-workspace value="Еиқәырхатәуп Акаталог Апроект ҳасабла"/>
<tab-untitled-string value="аҿыц "/> <tab-untitled-string value="аҿыц "/>

View File

@ -1762,7 +1762,6 @@ Notepad++ сделает резервную копию вашего старог
<find-result-title-info-selections value="(найдено $INT_REPLACE1$ совпадений в $INT_REPLACE2$ выделениях из $INT_REPLACE3$)"/> <find-result-title-info-selections value="(найдено $INT_REPLACE1$ совпадений в $INT_REPLACE2$ выделениях из $INT_REPLACE3$)"/>
<find-result-title-info-extra value=" - Режим Фильтрации Строк: только отображает результаты фильтрования"/> <find-result-title-info-extra value=" - Режим Фильтрации Строк: только отображает результаты фильтрования"/>
<find-result-hits value="(совпадений: $INT_REPLACE$)"/> <find-result-hits value="(совпадений: $INT_REPLACE$)"/>
<find-result-hits-and-line-hits value="($INT_REPLACE1$ совпадений в $INT_REPLACE2$ строках)"/>
<find-regex-zero-length-match value="совпадение нулевой длины"/> <find-regex-zero-length-match value="совпадение нулевой длины"/>
<session-save-folder-as-workspace value="Сохранить Папку как Проект"/> <session-save-folder-as-workspace value="Сохранить Папку как Проект"/>
<tab-untitled-string value="новый "/> <tab-untitled-string value="новый "/>

View File

@ -880,7 +880,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW);
activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW);
_mainEditView.getFocus(); _mainEditView.grabFocus();
return TRUE; return TRUE;
} }
@ -2566,7 +2566,20 @@ void Notepad_plus::checkClipboard()
if (!NppParameters::getInstance().getSVP()._lineCopyCutWithoutSelection) if (!NppParameters::getInstance().getSVP()._lineCopyCutWithoutSelection)
{ {
enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR); enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR);
enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR);
if (hasSelection)
{
enableCommand(IDM_EDIT_COPY, true, MENU | TOOLBAR);
}
else if (_findReplaceDlg.allowCopyAction())
{
enableCommand(IDM_EDIT_COPY, false, TOOLBAR);
enableCommand(IDM_EDIT_COPY, true, MENU);
}
else
{
enableCommand(IDM_EDIT_COPY, false, MENU | TOOLBAR);
}
} }
enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR); enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR);
enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR); enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR);
@ -4752,7 +4765,7 @@ int Notepad_plus::switchEditViewTo(int gid)
if (currentView() == gid) if (currentView() == gid)
{ {
//make sure focus is ok, then leave //make sure focus is ok, then leave
_pEditView->getFocus(); //set the focus _pEditView->grabFocus(); //set the focus
return gid; return gid;
} }
@ -4768,7 +4781,7 @@ int Notepad_plus::switchEditViewTo(int gid)
std::swap(_pEditView, _pNonEditView); std::swap(_pEditView, _pNonEditView);
_pEditView->beSwitched(); _pEditView->beSwitched();
_pEditView->getFocus(); //set the focus _pEditView->grabFocus(); //set the focus
if (_pDocMap) if (_pDocMap)
{ {
@ -5939,7 +5952,7 @@ void Notepad_plus::fullScreenToggle()
int y = nppRect.top; int y = nppRect.top;
::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE);
_pEditView->getFocus(); _pEditView->grabFocus();
} }
else //toggle fullscreen off else //toggle fullscreen off
{ {
@ -6073,7 +6086,7 @@ void Notepad_plus::postItToggle()
int y = nppRect.top + 1; int y = nppRect.top + 1;
::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE);
_pEditView->getFocus(); _pEditView->grabFocus();
} }
else //PostIt enabled, disable it else //PostIt enabled, disable it
{ {
@ -7697,7 +7710,7 @@ void Notepad_plus::launchDocMap()
_pDocMap->wrapMap(); _pDocMap->wrapMap();
_pDocMap->display(); _pDocMap->display();
_pEditView->getFocus(); _pEditView->grabFocus();
} }

View File

@ -2257,7 +2257,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
if (wParam != WA_INACTIVE && _pEditView && _pNonEditView) if (wParam != WA_INACTIVE && _pEditView && _pNonEditView)
{ {
_pEditView->getFocus(); _pEditView->grabFocus();
auto x = _pEditView->execute(SCI_GETXOFFSET); auto x = _pEditView->execute(SCI_GETXOFFSET);
_pEditView->execute(SCI_SETXOFFSET, x); _pEditView->execute(SCI_SETXOFFSET, x);
x = _pNonEditView->execute(SCI_GETXOFFSET); x = _pNonEditView->execute(SCI_GETXOFFSET);
@ -2880,7 +2880,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
//case WM_LBUTTONDBLCLK: //case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP : case WM_LBUTTONUP :
{ {
_pEditView->getFocus(); _pEditView->grabFocus();
::ShowWindow(hwnd, SW_SHOW); ::ShowWindow(hwnd, SW_SHOW);
_dockingManager.showFloatingContainers(true); _dockingManager.showFloatingContainers(true);
restoreMinimizeDialogs(); restoreMinimizeDialogs();

View File

@ -895,7 +895,7 @@ void Notepad_plus::command(int id)
{ {
if (_pDocumentListPanel && _pDocumentListPanel->isVisible()) if (_pDocumentListPanel && _pDocumentListPanel->isVisible())
{ {
_pDocumentListPanel->getFocus(); _pDocumentListPanel->grabFocus();
} }
else else
{ {
@ -1035,7 +1035,7 @@ void Notepad_plus::command(int id)
{ {
if (_pFuncList && _pFuncList->isVisible()) if (_pFuncList && _pFuncList->isVisible())
{ {
_pFuncList->getFocus(); _pFuncList->grabFocus();
} }
else else
{ {

View File

@ -577,10 +577,15 @@ bool Finder::notify(SCNotification *notification)
case SCN_PAINTED : case SCN_PAINTED :
if (isDoubleClicked) if (isDoubleClicked)
{ {
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
isDoubleClicked = false; isDoubleClicked = false;
} }
break; break;
case SCN_UPDATEUI:
::SendMessage(_hParent, NPPM_INTERNAL_CHECKUNDOREDOSTATE, 0, 0);
break;
} }
return false; return false;
} }
@ -2352,7 +2357,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
setStatusbarMessage(result, FSMessage, reasonMsg); setStatusbarMessage(result, FSMessage, reasonMsg);
} }
getFocus(); grabFocus();
} }
} }
return TRUE; return TRUE;
@ -2401,7 +2406,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
if (isMacroRecording) if (isMacroRecording)
saveInMacro(wParam, FR_OP_FIND); saveInMacro(wParam, FR_OP_FIND);
getFocus(); grabFocus();
} }
} }
return TRUE; return TRUE;
@ -2451,7 +2456,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
setStatusbarMessage(result, FSMessage, reasonMsg); setStatusbarMessage(result, FSMessage, reasonMsg);
} }
getFocus(); grabFocus();
} }
} }
return TRUE; return TRUE;
@ -2874,7 +2879,7 @@ bool FindReplaceDlg::processFindNext(const wchar_t *txt2find, const FindOption *
// if the dialog is not shown, pass the focus to his parent(ie. Notepad++) // if the dialog is not shown, pass the focus to his parent(ie. Notepad++)
if (!::IsWindowVisible(_hSelf)) if (!::IsWindowVisible(_hSelf))
{ {
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
} }
else else
{ {
@ -3676,7 +3681,7 @@ void FindReplaceDlg::findAllIn(InWhat op)
{ {
// Show finder // Show finder
_pFinder->display(); _pFinder->display();
getFocus(); // no hits grabFocus(); // no hits
} }
} }
else // error - search folder doesn't exist else // error - search folder doesn't exist
@ -3776,7 +3781,7 @@ Finder * FindReplaceDlg::createFinder()
// Show finder // Show finder
pFinder->display(); pFinder->display();
pFinder->_scintView.getFocus(); pFinder->_scintView.grabFocus();
return pFinder; return pFinder;
} }
@ -5905,7 +5910,7 @@ intptr_t CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPA
{ {
case IDCANCEL : case IDCANCEL :
(*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); (*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC);
(*(_pFRDlg->_ppEditView))->getFocus(); (*(_pFRDlg->_ppEditView))->grabFocus();
display(false); display(false);
return TRUE; return TRUE;

View File

@ -352,10 +352,21 @@ public :
if (_pFinder) if (_pFinder)
{ {
_pFinder->display(); _pFinder->display();
_pFinder->_scintView.getFocus(); _pFinder->_scintView.grabFocus();
} }
}; };
bool allowCopyAction() {
HWND focusedHwnd = GetFocus();
Finder* finder = getFinderFrom(focusedHwnd);
if (finder)
{
return finder->_scintView.hasSelection();
}
return false;
};
HWND getHFindResults() { HWND getHFindResults() {
if (_pFinder) if (_pFinder)
return _pFinder->_scintView.getHSelf(); return _pFinder->_scintView.getHSelf();

View File

@ -118,7 +118,7 @@ intptr_t CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
notification.nmhdr.idFrom = ::GetDlgCtrlID(_hSelf); notification.nmhdr.idFrom = ::GetDlgCtrlID(_hSelf);
::SendMessage(_hParent, WM_NOTIFY, LINKTRIGGERED, reinterpret_cast<LPARAM>(&notification)); ::SendMessage(_hParent, WM_NOTIFY, LINKTRIGGERED, reinterpret_cast<LPARAM>(&notification));
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
return TRUE; return TRUE;
} }

View File

@ -353,7 +353,7 @@ intptr_t CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
} }
} }
(*_ppEditView)->execute(SCI_ENDUNDOACTION); (*_ppEditView)->execute(SCI_ENDUNDOACTION);
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
return TRUE; return TRUE;
} }
case IDC_COL_TEXT_RADIO : case IDC_COL_TEXT_RADIO :

View File

@ -176,7 +176,7 @@ void AnsiCharPanel::insertChar(unsigned char char2insert) const
(*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>("")); (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));
size_t len = (char2insert < 128) ? 1 : strlen(multiByteStr); size_t len = (char2insert < 128) ? 1 : strlen(multiByteStr);
(*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast<LPARAM>(multiByteStr)); (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast<LPARAM>(multiByteStr));
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
} }
void AnsiCharPanel::insertString(LPWSTR string2insert) const void AnsiCharPanel::insertString(LPWSTR string2insert) const
@ -203,5 +203,5 @@ void AnsiCharPanel::insertString(LPWSTR string2insert) const
(*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>("")); (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));
size_t len = strlen(multiByteStr); size_t len = strlen(multiByteStr);
(*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast<LPARAM>(multiByteStr)); (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast<LPARAM>(multiByteStr));
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
} }

View File

@ -287,7 +287,7 @@ intptr_t CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam
(*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>("")); (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));
(*_ppEditView)->execute(SCI_ADDTEXT, strlen(c), reinterpret_cast<LPARAM>(c)); (*_ppEditView)->execute(SCI_ADDTEXT, strlen(c), reinterpret_cast<LPARAM>(c));
(*_ppEditView)->getFocus(); (*_ppEditView)->grabFocus();
delete[] c; delete[] c;
} }
} }

View File

@ -1008,7 +1008,7 @@ bool WordStyleDlg::goToSection(const wchar_t* sectionNames)
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, i, 0); ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, i, 0);
setVisualFromStyleList(); setVisualFromStyleList();
getFocus(); grabFocus();
return true; return true;
} }

View File

@ -449,7 +449,7 @@ bool FileBrowser::selectItemFromPath(const wstring& itemPath) const
if (foundItem) if (foundItem)
{ {
_treeView.selectItem(foundItem); _treeView.selectItem(foundItem);
_treeView.getFocus(); _treeView.grabFocus();
return true; return true;
} }
} }

View File

@ -104,7 +104,7 @@ bool PreferenceDlg::goToSection(size_t iPage, intptr_t ctrlID)
{ {
::SendDlgItemMessage(_hSelf, IDC_LIST_DLGTITLE, LB_SETCURSEL, iPage, 0); ::SendDlgItemMessage(_hSelf, IDC_LIST_DLGTITLE, LB_SETCURSEL, iPage, 0);
showDialogByIndex(iPage); showDialogByIndex(iPage);
getFocus(); grabFocus();
if (ctrlID != -1) if (ctrlID != -1)
{ {
@ -2047,7 +2047,7 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
} }
NppDarkMode::refreshDarkMode(_hSelf, forceRefresh); NppDarkMode::refreshDarkMode(_hSelf, forceRefresh);
getFocus(); // to make black mode title bar appear grabFocus(); // to make black mode title bar appear
return TRUE; return TRUE;
} }

View File

@ -29,61 +29,52 @@ public:
//@} //@}
virtual void init(HINSTANCE hInst, HWND parent) virtual void init(HINSTANCE hInst, HWND parent) {
{
_hInst = hInst; _hInst = hInst;
_hParent = parent; _hParent = parent;
} }
virtual void destroy() = 0; virtual void destroy() = 0;
virtual void display(bool toShow = true) const virtual void display(bool toShow = true) const {
{
::ShowWindow(_hSelf, toShow ? SW_SHOW : SW_HIDE); ::ShowWindow(_hSelf, toShow ? SW_SHOW : SW_HIDE);
} }
virtual void reSizeTo(RECT & rc) // should NEVER be const !!! virtual void reSizeTo(RECT & rc) { // should NEVER be const !!!
{
::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE); ::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE);
redraw(); redraw();
} }
virtual void reSizeToWH(RECT& rc) // should NEVER be const !!! virtual void reSizeToWH(RECT& rc) { // should NEVER be const !!!
{
::MoveWindow(_hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); ::MoveWindow(_hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
redraw(); redraw();
} }
virtual void redraw(bool forceUpdate = false) const virtual void redraw(bool forceUpdate = false) const {
{
::InvalidateRect(_hSelf, nullptr, TRUE); ::InvalidateRect(_hSelf, nullptr, TRUE);
if (forceUpdate) if (forceUpdate)
::UpdateWindow(_hSelf); ::UpdateWindow(_hSelf);
} }
virtual void getClientRect(RECT & rc) const virtual void getClientRect(RECT & rc) const {
{
::GetClientRect(_hSelf, &rc); ::GetClientRect(_hSelf, &rc);
} }
virtual void getWindowRect(RECT & rc) const virtual void getWindowRect(RECT & rc) const {
{
::GetWindowRect(_hSelf, &rc); ::GetWindowRect(_hSelf, &rc);
} }
virtual int getWidth() const virtual int getWidth() const {
{
RECT rc; RECT rc;
::GetClientRect(_hSelf, &rc); ::GetClientRect(_hSelf, &rc);
return (rc.right - rc.left); return (rc.right - rc.left);
} }
virtual int getHeight() const virtual int getHeight() const {
{
RECT rc; RECT rc;
::GetClientRect(_hSelf, &rc); ::GetClientRect(_hSelf, &rc);
if (::IsWindowVisible(_hSelf) == TRUE) if (::IsWindowVisible(_hSelf) == TRUE)
@ -96,8 +87,7 @@ public:
return (::IsWindowVisible(_hSelf)?true:false); return (::IsWindowVisible(_hSelf)?true:false);
} }
HWND getHSelf() const HWND getHSelf() const {
{
return _hSelf; return _hSelf;
} }
@ -105,13 +95,11 @@ public:
return _hParent; return _hParent;
} }
void getFocus() const { void grabFocus() const {
::SetFocus(_hSelf); ::SetFocus(_hSelf);
} }
HINSTANCE getHinst() const HINSTANCE getHinst() const {
{
//assert(_hInst != 0);
return _hInst; return _hInst;
} }