From fbd4a402143082178a006891e3a055dd332b334f Mon Sep 17 00:00:00 2001 From: Alan Kilborn Date: Wed, 14 Feb 2024 08:10:22 -0500 Subject: [PATCH] Fix context menu popup location issue Make context menu popup location at current text position when invoked via keyboard. Fix #14727, close #14730 --- PowerEditor/src/NppBigSwitch.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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; } }