RMichelsen / Nvy

Nvy - A Neovim client in C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot enter diacritic letters

EtiamNullam opened this issue · comments

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.

commented

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]>.

if (ctrl_down && wchar) {

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.

commented

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

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

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