RMichelsen / Nvy

Nvy - A Neovim client in C++
MIT License
333 stars 28 forks source link

Cannot enter diacritic letters #99

Closed EtiamNullam closed 1 year ago

EtiamNullam commented 1 year ago

Attempting to enter Polish diacritic characters just exits the insert mode instead of inserting them.

For example I would use ALT+L to get Ł. If I press CTRL-V to insert them as they are and attempting to insert ALT+L I will receive <M-C-L>, while on v0.3.6 on US layout <M-L> would be printed, and desired character appears on Polish layout. Seems like Nvy wrongly assumes that CTRL is also held.

Seems like its a regression bug that appeared in 0.3.7, 0.3.6 is fine.

Zorbn commented 1 year ago

Most likely caused by #95. The problem is that AltGr is represented as Alt+Ctrl on Windows so there isn't a way to distinguish between the two. One way to fix this would be to ignore Ctrl when Alt is also pressed, although if we did that it wouldn't be possible to bind keys combinations like <C-A-[key]>.

https://github.com/RMichelsen/Nvy/blob/c1628ec5d4f8f430cd0d61a9e831766d4976e7af/src/main.cpp#L232

rehael commented 1 year ago
diff --git a/src/main.cpp b/src/main.cpp
index 9faa38b..8821b1c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -227,9 +227,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
                                }
                        }

+                       bool altgr_down = (GetKeyState(VK_RMENU) & 0x80) != 0;
                        bool ctrl_down = (GetKeyState(VK_CONTROL) & 0x80) != 0;
                        wchar_t wchar = static_cast<wchar_t>(MapVirtualKeyEx(wparam, MAPVK_VK_TO_CHAR, context->hkl));
-                       if (ctrl_down && wchar) {
+                       if (!altgr_down && ctrl_down && wchar) {
                                NvimSendSysChar(context->nvim, wchar);
                                return 0;
                        }

This solves the problem for me. YMMV.

Zorbn commented 1 year ago

@rehael That seems like a good solution, certainly better than how it currently works, probably worth a PR.

rehael commented 1 year ago

PR linked. But frankly I'm not especially proud of that quick hack. ;)

RMichelsen commented 1 year ago

Yes unfortunately the key handlings is hacky in general atm, but I agree this is probably an improvement for now :), merging.