Skip to content

Commit 2d84ecf

Browse files
committed
Allow Cut/Copy/Paste while still holding LMB
Fix the behavior of Notepad++ v8.6.1 and newer when if you hold the left mouse button, you cannot use the usual Ctrl+X/C/V. Due to the N++ has registered the Ctrl+X/C/V accelerators in v8.6.1+ (before, the Scintilla handled that), we have to detect such a situation before calling the N++ TranslateAccelerator in the main message loop. In such a situation we cannot use the usual WM_KEYDOWN message handler, as that TranslateAccelerator eats any Ctrl&X keydowns from the queue. At the WM_KEYUP it works but behaves slightly different than the users expect.
1 parent d6eadf1 commit 2d84ecf

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

PowerEditor/src/Notepad_plus_Window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class Notepad_plus_Window : public Window
6868
DPIManagerV2::loadIcon(hinst, MAKEINTRESOURCE(IDI_M30ICON), ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), icon);
6969
}
7070

71+
bool isCurrentScintillaEditViewWnd(HWND hWndToCheck) const {
72+
return (hWndToCheck == _notepad_plus_plus_core._pEditView->getHSelf());
73+
}
74+
7175
private:
7276
Notepad_plus _notepad_plus_plus_core;
7377
static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

PowerEditor/src/winmain.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,28 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance
846846
// if the message doesn't belong to the notepad_plus_plus's dialog
847847
if (!notepad_plus_plus.isDlgsMsg(&msg))
848848
{
849+
// enable the standard Ctrl+X/C/V while still holding the left mouse button (from the previous text selection etc...)
850+
if ((msg.message == WM_KEYDOWN) &&
851+
((msg.wParam == 'X') || (msg.wParam == 'C') || (msg.wParam == 'V')) &&
852+
((::GetKeyState(VK_LBUTTON) & 0x8000) && (::GetKeyState(VK_CONTROL) & 0x8000)))
853+
{
854+
if (notepad_plus_plus.isCurrentScintillaEditViewWnd(msg.hwnd)) // allow in editor-wnd only (change it to if(msg.hwnd!=NULL) to be app-wide)
855+
{
856+
switch (msg.wParam)
857+
{
858+
case 'X':
859+
::SendMessage(notepad_plus_plus.getHSelf(), WM_COMMAND, IDM_EDIT_CUT, 0);
860+
break;
861+
case 'C':
862+
::SendMessage(notepad_plus_plus.getHSelf(), WM_COMMAND, IDM_EDIT_COPY, 0);
863+
break;
864+
case 'V':
865+
::SendMessage(notepad_plus_plus.getHSelf(), WM_COMMAND, IDM_EDIT_PASTE, 0);
866+
break;
867+
}
868+
}
869+
}
870+
849871
if (::TranslateAccelerator(notepad_plus_plus.getHSelf(), notepad_plus_plus.getAccTable(), &msg) == 0)
850872
{
851873
::TranslateMessage(&msg);

0 commit comments

Comments
 (0)