Browse Source

Fix context menu popup location issue

Make context menu popup location at current text position when invoked via keyboard.

Fix #14727, close #14730
pull/14789/head
Alan Kilborn 9 months ago committed by Don Ho
parent
commit
fbd4a40214
  1. 23
      PowerEditor/src/NppBigSwitch.cpp

23
PowerEditor/src/NppBigSwitch.cpp

@ -19,6 +19,7 @@
#include <shlwapi.h>
#include <uxtheme.h> // for EnableThemeDialogTexture
#include <format>
#include <Windowsx.h> // 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<HWND>(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<MenuItemUnit>& 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<LONG>(_pEditView->execute(SCI_POINTXFROMPOSITION, 0, caretPos));
p.y = static_cast<LONG>(_pEditView->execute(SCI_POINTYFROMPOSITION, 0, caretPos));
::ClientToScreen(activeViewHwnd, &p);
}
scintillaContextmenu.display(p);
return TRUE;
}
}

Loading…
Cancel
Save