diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index de9397aa8..38bbce3dd 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2629,10 +2629,16 @@ void Notepad_plus::maintainIndentation(TCHAR ch) } } +BOOL Notepad_plus::processFindAccel(MSG *msg) const +{ + if (not ::IsChild(_findReplaceDlg.getHSelf(), ::GetFocus())) + return FALSE; + return ::TranslateAccelerator(_findReplaceDlg.getHSelf(), _accelerator.getFindAccTable(), msg); +} BOOL Notepad_plus::processIncrFindAccel(MSG *msg) const { - if (!::IsChild(_incrementFindDlg.getHSelf(), ::GetFocus())) + if (not ::IsChild(_incrementFindDlg.getHSelf(), ::GetFocus())) return FALSE; return ::TranslateAccelerator(_incrementFindDlg.getHSelf(), _accelerator.getIncrFindAccTable(), msg); } diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index a7cc78e21..b6344e409 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -514,6 +514,7 @@ private: enum LangType menuID2LangType(int cmdID); BOOL processIncrFindAccel(MSG *msg) const; + BOOL processFindAccel(MSG *msg) const; void checkMenuItem(int itemID, bool willBeChecked) const { ::CheckMenuItem(_mainMenuHandle, itemID, MF_BYCOMMAND | (willBeChecked?MF_CHECKED:MF_UNCHECKED)); diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 89924c43b..92b1c54d0 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -308,6 +308,9 @@ bool Notepad_plus_Window::isDlgsMsg(MSG *msg) const if (_notepad_plus_plus_core.processIncrFindAccel(msg)) return true; + if (_notepad_plus_plus_core.processFindAccel(msg)) + return true; + if (::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg)) return true; } diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 9e542fba1..05491bc8c 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -813,7 +813,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM bool isMacroRecording = (::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS,0,0) == MACRO_RECORDING_IN_PROGRESS); NppParameters *nppParamInst = NppParameters::getInstance(); FindHistory & findHistory = nppParamInst->getFindHistory(); - switch (wParam) + switch (LOWORD(wParam)) { //Single actions case IDCANCEL: @@ -844,6 +844,10 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM } return TRUE; + case IDM_SEARCH_FIND: + goToCenter(); + return TRUE; + case IDREPLACE : { LongRunningOperation op; diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index 37e2d7744..27a2ec9d4 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -483,10 +483,10 @@ INT_PTR CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) // return true if one of CommandShortcuts is deleted. Otherwise false. void Accelerator::updateShortcuts() { - vector IFAccIds; - IFAccIds.push_back(IDM_SEARCH_FINDNEXT); - IFAccIds.push_back(IDM_SEARCH_FINDPREV); - IFAccIds.push_back(IDM_SEARCH_FINDINCREMENT); + vector incrFindAccIds; + incrFindAccIds.push_back(IDM_SEARCH_FINDNEXT); + incrFindAccIds.push_back(IDM_SEARCH_FINDPREV); + incrFindAccIds.push_back(IDM_SEARCH_FINDINCREMENT); NppParameters *pNppParam = NppParameters::getInstance(); @@ -503,8 +503,9 @@ void Accelerator::updateShortcuts() if (_pAccelArray) delete [] _pAccelArray; _pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd]; - vector IFAcc; + vector incrFindAcc; + ACCEL *pSearchFindAccel = nullptr; int offset = 0; size_t i = 0; //no validation performed, it might be that invalid shortcuts are being used by default. Allows user to 'hack', might be a good thing @@ -512,13 +513,16 @@ void Accelerator::updateShortcuts() { if (shortcuts[i].isEnabled()) { - _pAccelArray[offset].cmd = (WORD)(shortcuts[i].getID()); + _pAccelArray[offset].cmd = static_cast(shortcuts[i].getID()); _pAccelArray[offset].fVirt = shortcuts[i].getAcceleratorModifiers(); _pAccelArray[offset].key = shortcuts[i].getKeyCombo()._key; // Special extra handling for shortcuts shared by Incremental Find dialog - if (std::find(IFAccIds.begin(), IFAccIds.end(), shortcuts[i].getID()) != IFAccIds.end()) - IFAcc.push_back(_pAccelArray[offset]); + if (std::find(incrFindAccIds.begin(), incrFindAccIds.end(), shortcuts[i].getID()) != incrFindAccIds.end()) + incrFindAcc.push_back(_pAccelArray[offset]); + + if (shortcuts[i].getID() == IDM_SEARCH_FIND) + pSearchFindAccel = &_pAccelArray[offset]; ++offset; } @@ -569,14 +573,28 @@ void Accelerator::updateShortcuts() if (_hIncFindAccTab) ::DestroyAcceleratorTable(_hIncFindAccTab); - size_t nb = IFAcc.size(); - ACCEL *tmpAccelArray = new ACCEL[nb]; + size_t nb = incrFindAcc.size(); + ACCEL *tmpIncrFindAccelArray = new ACCEL[nb]; for (i = 0; i < nb; ++i) { - tmpAccelArray[i] = IFAcc[i]; + tmpIncrFindAccelArray[i] = incrFindAcc[i]; + } + _hIncFindAccTab = ::CreateAcceleratorTable(tmpIncrFindAccelArray, static_cast(nb)); + delete [] tmpIncrFindAccelArray; + + if (_hIncFindAccTab) + ::DestroyAcceleratorTable(_hIncFindAccTab); + + + if (_hFindAccTab) + ::DestroyAcceleratorTable(_hFindAccTab); + ACCEL *tmpFindAccelArray = new ACCEL[1]; + if (pSearchFindAccel != nullptr) + { + tmpFindAccelArray[0] = *pSearchFindAccel; + _hFindAccTab = ::CreateAcceleratorTable(tmpFindAccelArray, 1); + delete[] tmpFindAccelArray; } - _hIncFindAccTab = ::CreateAcceleratorTable(tmpAccelArray, static_cast(nb)); - delete [] tmpAccelArray; return; } diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index 4eaa924af..c4c77f301 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -340,12 +340,14 @@ private : class Accelerator { //Handles accelerator keys for Notepad++ menu, including custom commands friend class ShortcutMapper; public: - Accelerator() :_hAccelMenu(NULL), _hMenuParent(NULL), _hAccTable(NULL), _hIncFindAccTab(NULL), _pAccelArray(NULL), _nbAccelItems(0){}; + Accelerator() {}; ~Accelerator() { if (_hAccTable) ::DestroyAcceleratorTable(_hAccTable); if (_hIncFindAccTab) ::DestroyAcceleratorTable(_hIncFindAccTab); + if (_hFindAccTab) + ::DestroyAcceleratorTable(_hFindAccTab); if (_pAccelArray) delete [] _pAccelArray; }; @@ -356,17 +358,19 @@ public: }; HACCEL getAccTable() const {return _hAccTable;}; HACCEL getIncrFindAccTable() const { return _hIncFindAccTab; }; + HACCEL getFindAccTable() const { return _hFindAccTab; }; void updateShortcuts(); void updateFullMenu(); private: - HMENU _hAccelMenu; - HWND _hMenuParent; - HACCEL _hAccTable; - HACCEL _hIncFindAccTab; - ACCEL *_pAccelArray; - int _nbAccelItems; + HMENU _hAccelMenu = nullptr; + HWND _hMenuParent = nullptr; + HACCEL _hAccTable = nullptr; + HACCEL _hIncFindAccTab = nullptr; + HACCEL _hFindAccTab = nullptr; + ACCEL *_pAccelArray = nullptr; + int _nbAccelItems = 0; void updateMenuItemByCommand(CommandShortcut csc); };