diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index b4c352dca..809958a49 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -19,6 +19,7 @@ #include #include // for EnableThemeDialogTexture #include +#include // for GET_X_LPARAM, GET_Y_LPARAM #include "Notepad_plus_Window.h" #include "TaskListDlg.h" #include "ImageListSet.h" @@ -1967,20 +1968,34 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa } else { - if ((HWND(wParam) == _mainEditView.getHSelf()) || (HWND(wParam) == _subEditView.getHSelf())) + HWND activeViewHwnd = reinterpret_cast(wParam); + + if ((activeViewHwnd == _mainEditView.getHSelf()) || (activeViewHwnd == _subEditView.getHSelf())) { - if ((HWND(wParam) == _mainEditView.getHSelf())) + if (activeViewHwnd == _mainEditView.getHSelf()) switchEditViewTo(MAIN_VIEW); else switchEditViewTo(SUB_VIEW); - POINT p; - ::GetCursorPos(&p); ContextMenu scintillaContextmenu; + std::vector& tmp = nppParam.getContextMenuItems(); bool copyLink = (_pEditView->getSelectedTextCount() == 0) && _pEditView->getIndicatorRange(URL_INDIC); scintillaContextmenu.create(hwnd, tmp, _mainMenuHandle, copyLink); + + POINT p; + p.x = GET_X_LPARAM(lParam); + p.y = GET_Y_LPARAM(lParam); + if ((p.x == -1) && (p.y == -1)) + { + // context menu activated via keyboard; pop up at text caret position + auto caretPos = _pEditView->execute(SCI_GETCURRENTPOS); + p.x = static_cast(_pEditView->execute(SCI_POINTXFROMPOSITION, 0, caretPos)); + p.y = static_cast(_pEditView->execute(SCI_POINTYFROMPOSITION, 0, caretPos)); + ::ClientToScreen(activeViewHwnd, &p); + } scintillaContextmenu.display(p); + return TRUE; } }