From c24444acfe28644af992d5a6253be0b145c300b1 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 16 Nov 2024 17:52:14 +0100 Subject: [PATCH] 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 --- .../installer/nativeLang/abkhazian.xml | 1 - PowerEditor/installer/nativeLang/russian.xml | 1 - PowerEditor/src/Notepad_plus.cpp | 27 ++++++++++---- PowerEditor/src/NppBigSwitch.cpp | 4 +-- PowerEditor/src/NppCommands.cpp | 4 +-- .../src/ScintillaComponent/FindReplaceDlg.cpp | 21 ++++++----- .../src/ScintillaComponent/FindReplaceDlg.h | 13 ++++++- .../src/ScintillaComponent/GoToLineDlg.cpp | 2 +- .../src/ScintillaComponent/columnEditor.cpp | 2 +- .../AnsiCharPanel/ansiCharPanel.cpp | 4 +-- .../clipboardHistoryPanel.cpp | 2 +- .../WinControls/ColourPicker/WordStyleDlg.cpp | 2 +- .../WinControls/FileBrowser/fileBrowser.cpp | 2 +- .../WinControls/Preference/preferenceDlg.cpp | 4 +-- PowerEditor/src/WinControls/Window.h | 36 +++++++------------ 15 files changed, 70 insertions(+), 55 deletions(-) diff --git a/PowerEditor/installer/nativeLang/abkhazian.xml b/PowerEditor/installer/nativeLang/abkhazian.xml index f1208252c..dc85ab502 100644 --- a/PowerEditor/installer/nativeLang/abkhazian.xml +++ b/PowerEditor/installer/nativeLang/abkhazian.xml @@ -1484,7 +1484,6 @@ Updated to v8.2.1: - diff --git a/PowerEditor/installer/nativeLang/russian.xml b/PowerEditor/installer/nativeLang/russian.xml index dc5913419..b2225da24 100644 --- a/PowerEditor/installer/nativeLang/russian.xml +++ b/PowerEditor/installer/nativeLang/russian.xml @@ -1762,7 +1762,6 @@ Notepad++ сделает резервную копию вашего старог - diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 9165c0cf9..cc8be2af0 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -880,7 +880,7 @@ LRESULT Notepad_plus::init(HWND hwnd) activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); - _mainEditView.getFocus(); + _mainEditView.grabFocus(); return TRUE; } @@ -2566,7 +2566,20 @@ void Notepad_plus::checkClipboard() if (!NppParameters::getInstance().getSVP()._lineCopyCutWithoutSelection) { 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_DELETE, hasSelection, MENU | TOOLBAR); @@ -4752,7 +4765,7 @@ int Notepad_plus::switchEditViewTo(int gid) if (currentView() == gid) { //make sure focus is ok, then leave - _pEditView->getFocus(); //set the focus + _pEditView->grabFocus(); //set the focus return gid; } @@ -4768,7 +4781,7 @@ int Notepad_plus::switchEditViewTo(int gid) std::swap(_pEditView, _pNonEditView); _pEditView->beSwitched(); - _pEditView->getFocus(); //set the focus + _pEditView->grabFocus(); //set the focus if (_pDocMap) { @@ -5939,7 +5952,7 @@ void Notepad_plus::fullScreenToggle() int y = nppRect.top; ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); - _pEditView->getFocus(); + _pEditView->grabFocus(); } else //toggle fullscreen off { @@ -6073,7 +6086,7 @@ void Notepad_plus::postItToggle() int y = nppRect.top + 1; ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); - _pEditView->getFocus(); + _pEditView->grabFocus(); } else //PostIt enabled, disable it { @@ -7697,7 +7710,7 @@ void Notepad_plus::launchDocMap() _pDocMap->wrapMap(); _pDocMap->display(); - _pEditView->getFocus(); + _pEditView->grabFocus(); } diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index c3dd2e321..5df0ca6e7 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2257,7 +2257,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { if (wParam != WA_INACTIVE && _pEditView && _pNonEditView) { - _pEditView->getFocus(); + _pEditView->grabFocus(); auto x = _pEditView->execute(SCI_GETXOFFSET); _pEditView->execute(SCI_SETXOFFSET, x); 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_LBUTTONUP : { - _pEditView->getFocus(); + _pEditView->grabFocus(); ::ShowWindow(hwnd, SW_SHOW); _dockingManager.showFloatingContainers(true); restoreMinimizeDialogs(); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 2a1db337a..f7a820304 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -895,7 +895,7 @@ void Notepad_plus::command(int id) { if (_pDocumentListPanel && _pDocumentListPanel->isVisible()) { - _pDocumentListPanel->getFocus(); + _pDocumentListPanel->grabFocus(); } else { @@ -1035,7 +1035,7 @@ void Notepad_plus::command(int id) { if (_pFuncList && _pFuncList->isVisible()) { - _pFuncList->getFocus(); + _pFuncList->grabFocus(); } else { diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 10f594ddf..d5476a0d0 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -577,10 +577,15 @@ bool Finder::notify(SCNotification *notification) case SCN_PAINTED : if (isDoubleClicked) { - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); isDoubleClicked = false; } break; + + case SCN_UPDATEUI: + ::SendMessage(_hParent, NPPM_INTERNAL_CHECKUNDOREDOSTATE, 0, 0); + break; + } return false; } @@ -2352,7 +2357,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA setStatusbarMessage(result, FSMessage, reasonMsg); } - getFocus(); + grabFocus(); } } return TRUE; @@ -2401,7 +2406,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND); - getFocus(); + grabFocus(); } } return TRUE; @@ -2451,7 +2456,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA setStatusbarMessage(result, FSMessage, reasonMsg); } - getFocus(); + grabFocus(); } } 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 (!::IsWindowVisible(_hSelf)) { - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); } else { @@ -3676,7 +3681,7 @@ void FindReplaceDlg::findAllIn(InWhat op) { // Show finder _pFinder->display(); - getFocus(); // no hits + grabFocus(); // no hits } } else // error - search folder doesn't exist @@ -3776,7 +3781,7 @@ Finder * FindReplaceDlg::createFinder() // Show finder pFinder->display(); - pFinder->_scintView.getFocus(); + pFinder->_scintView.grabFocus(); return pFinder; } @@ -5905,7 +5910,7 @@ intptr_t CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPA { case IDCANCEL : (*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); - (*(_pFRDlg->_ppEditView))->getFocus(); + (*(_pFRDlg->_ppEditView))->grabFocus(); display(false); return TRUE; diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h index 62b438cc7..36c278bfe 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h @@ -352,10 +352,21 @@ public : if (_pFinder) { _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() { if (_pFinder) return _pFinder->_scintView.getHSelf(); diff --git a/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp b/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp index 2ddbcfc86..2f40c4ee7 100644 --- a/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp @@ -118,7 +118,7 @@ intptr_t CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l notification.nmhdr.idFrom = ::GetDlgCtrlID(_hSelf); ::SendMessage(_hParent, WM_NOTIFY, LINKTRIGGERED, reinterpret_cast(¬ification)); - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); return TRUE; } diff --git a/PowerEditor/src/ScintillaComponent/columnEditor.cpp b/PowerEditor/src/ScintillaComponent/columnEditor.cpp index c26302357..f963443a3 100644 --- a/PowerEditor/src/ScintillaComponent/columnEditor.cpp +++ b/PowerEditor/src/ScintillaComponent/columnEditor.cpp @@ -353,7 +353,7 @@ intptr_t CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR } } (*_ppEditView)->execute(SCI_ENDUNDOACTION); - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); return TRUE; } case IDC_COL_TEXT_RADIO : diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp index 019402560..df3637444 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp @@ -176,7 +176,7 @@ void AnsiCharPanel::insertChar(unsigned char char2insert) const (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast("")); size_t len = (char2insert < 128) ? 1 : strlen(multiByteStr); (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast(multiByteStr)); - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); } void AnsiCharPanel::insertString(LPWSTR string2insert) const @@ -203,5 +203,5 @@ void AnsiCharPanel::insertString(LPWSTR string2insert) const (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast("")); size_t len = strlen(multiByteStr); (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast(multiByteStr)); - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); } diff --git a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp index efdffb6cb..7814c3a8a 100644 --- a/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp +++ b/PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp @@ -287,7 +287,7 @@ intptr_t CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast("")); (*_ppEditView)->execute(SCI_ADDTEXT, strlen(c), reinterpret_cast(c)); - (*_ppEditView)->getFocus(); + (*_ppEditView)->grabFocus(); delete[] c; } } diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index 2b636fbcb..198768ef1 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -1008,7 +1008,7 @@ bool WordStyleDlg::goToSection(const wchar_t* sectionNames) ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, i, 0); setVisualFromStyleList(); - getFocus(); + grabFocus(); return true; } diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 1494fb57e..e1818b037 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -449,7 +449,7 @@ bool FileBrowser::selectItemFromPath(const wstring& itemPath) const if (foundItem) { _treeView.selectItem(foundItem); - _treeView.getFocus(); + _treeView.grabFocus(); return true; } } diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index fa849211c..a8b4ea289 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -104,7 +104,7 @@ bool PreferenceDlg::goToSection(size_t iPage, intptr_t ctrlID) { ::SendDlgItemMessage(_hSelf, IDC_LIST_DLGTITLE, LB_SETCURSEL, iPage, 0); showDialogByIndex(iPage); - getFocus(); + grabFocus(); if (ctrlID != -1) { @@ -2047,7 +2047,7 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA } NppDarkMode::refreshDarkMode(_hSelf, forceRefresh); - getFocus(); // to make black mode title bar appear + grabFocus(); // to make black mode title bar appear return TRUE; } diff --git a/PowerEditor/src/WinControls/Window.h b/PowerEditor/src/WinControls/Window.h index 5f929792a..79a7fa349 100644 --- a/PowerEditor/src/WinControls/Window.h +++ b/PowerEditor/src/WinControls/Window.h @@ -29,61 +29,52 @@ public: //@} - virtual void init(HINSTANCE hInst, HWND parent) - { + virtual void init(HINSTANCE hInst, HWND parent) { _hInst = hInst; _hParent = parent; } 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); } - 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); 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); redraw(); } - virtual void redraw(bool forceUpdate = false) const - { + virtual void redraw(bool forceUpdate = false) const { ::InvalidateRect(_hSelf, nullptr, TRUE); if (forceUpdate) ::UpdateWindow(_hSelf); } - virtual void getClientRect(RECT & rc) const - { + virtual void getClientRect(RECT & rc) const { ::GetClientRect(_hSelf, &rc); } - virtual void getWindowRect(RECT & rc) const - { + virtual void getWindowRect(RECT & rc) const { ::GetWindowRect(_hSelf, &rc); } - virtual int getWidth() const - { + virtual int getWidth() const { RECT rc; ::GetClientRect(_hSelf, &rc); return (rc.right - rc.left); } - virtual int getHeight() const - { + virtual int getHeight() const { RECT rc; ::GetClientRect(_hSelf, &rc); if (::IsWindowVisible(_hSelf) == TRUE) @@ -96,8 +87,7 @@ public: return (::IsWindowVisible(_hSelf)?true:false); } - HWND getHSelf() const - { + HWND getHSelf() const { return _hSelf; } @@ -105,13 +95,11 @@ public: return _hParent; } - void getFocus() const { + void grabFocus() const { ::SetFocus(_hSelf); } - HINSTANCE getHinst() const - { - //assert(_hInst != 0); + HINSTANCE getHinst() const { return _hInst; }