From 4ce8706b744b86ae0f48a57303aad318c14ab9ba Mon Sep 17 00:00:00 2001
From: mitchell
Date: Fri, 27 Mar 2020 11:16:43 -0400
Subject: Backport: Bug [#2152]. Ignore Alt+Keypad keys that will result in a
WM_CHAR.
Backport of changeset 7961:6950bccc71ce.
---
doc/ScintillaDoc.html | 6 ++++++
doc/ScintillaHistory.html | 6 ++++++
win32/ScintillaWin.cxx | 33 +++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 46262e0a5..f3d5c9fd3 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -5494,6 +5494,12 @@ struct Sci_TextToFind {
If you are building a table, you might
want to use SCMOD_NORM, which has the value 0, to mean no modifiers.
+ On Win32, the numeric keypad with Alt pressed can be used to enter characters by number.
+ This can produce unexpected results in non-numlock mode when function keys are assigned so
+ potentially problematic keys are ignored. For example, setting
+ SCMOD_ALT,SCK_UP will only be active for the Up key on the
+ main cursor keys, not the numeric keypad.
+
SCI_ASSIGNCMDKEY(int keyDefinition, int sciCommand)
This assigns the given key definition to a Scintilla command identified by
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 884d0fa98..c6ed95a5a 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -584,6 +584,12 @@
CF_UNICODETEXT.
+ On Win32, the numeric keypad with Alt pressed can be used to enter characters by number.
+ This can produce unexpected results in non-numlock mode when function keys are assigned.
+ Potentially problematic keys like Alt+KeypadUp are now ignored.
+ Bug #2152.
+
+
Improve IME behaviour on GTK.
Set candidate position for windowed IME.
Improve location of candidate window.
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 21bd90288..298d0e022 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -168,6 +168,30 @@ bool KeyboardIsKeyDown(int key) noexcept {
return (::GetKeyState(key) & 0x80000000) != 0;
}
+bool KeyboardIsNumericKeypadFunction(uptr_t wParam, sptr_t lParam) {
+ // Bit 24 is the extended keyboard flag and the numeric keypad is non-extended
+ if ((lParam & (1 << 24)) != 0) {
+ // Not from the numeric keypad
+ return false;
+ }
+
+ switch (wParam) {
+ case VK_INSERT: // 0
+ case VK_END: // 1
+ case VK_DOWN: // 2
+ case VK_NEXT: // 3
+ case VK_LEFT: // 4
+ case VK_CLEAR: // 5
+ case VK_RIGHT: // 6
+ case VK_HOME: // 7
+ case VK_UP: // 8
+ case VK_PRIOR: // 9
+ return true;
+ default:
+ return false;
+ }
+}
+
}
class ScintillaWin; // Forward declaration for COM interface subobjects
@@ -1541,16 +1565,21 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
case WM_KEYDOWN: {
// Platform::DebugPrintf("Keydown %c %c%c%c%c %x %x\n",
// iMessage == WM_KEYDOWN ? 'K' : 'S',
- // (lParam & 1 << 24) ? '-' : 'E',
+ // (lParam & (1 << 24)) ? 'E' : '-',
// KeyboardIsKeyDown(VK_SHIFT) ? 'S' : '-',
// KeyboardIsKeyDown(VK_CONTROL) ? 'C' : '-',
// KeyboardIsKeyDown(VK_MENU) ? 'A' : '-',
// wParam, lParam);
lastKeyDownConsumed = false;
+ const bool altDown = KeyboardIsKeyDown(VK_MENU);
+ if (altDown && KeyboardIsNumericKeypadFunction(wParam, lParam)) {
+ // Don't interpret these as they may be characters entered by number.
+ return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
+ }
const int ret = KeyDownWithModifiers(KeyTranslate(static_cast(wParam)),
ModifierFlags(KeyboardIsKeyDown(VK_SHIFT),
KeyboardIsKeyDown(VK_CONTROL),
- KeyboardIsKeyDown(VK_MENU)),
+ altDown),
&lastKeyDownConsumed);
if (!ret && !lastKeyDownConsumed) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
--
cgit v1.2.3