Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neovide ignores 'alt+' codes on Windows #2449

Open
fautore opened this issue Mar 28, 2024 · 3 comments
Open

neovide ignores 'alt+' codes on Windows #2449

fautore opened this issue Mar 28, 2024 · 3 comments
Labels
bug Something isn't working keyboard Input Catch all category for keyboard issues windows Specific to Windows and not investigable on other platforms

Comments

@fautore
Copy link

fautore commented Mar 28, 2024

Describe the bug
Neovide running on Windows ignores 'alt+' codes to paste unicode characters that are not present in standard keyboards.

To Reproduce

  1. Open a neovide in Windows on a writable buffer
  2. Go into insert mode
  3. press <alt> + <whathever number combination> (i tried alt+96 (`) and alt+126 (~))
  4. relase <alt>
  5. input ignored

Expected behavior
The character should be inserted into the buffer after releasing

Desktop (please complete the following information):

  • OS: Windows 11
  • Neovide Version 0.11.2
  • Neovim Version 0.9.1

logs
I can provide logs when running the steps to reproduce, if necessary

Additional context
https://www.alt-codes.net/

@fautore fautore added the bug Something isn't working label Mar 28, 2024
@fautore fautore changed the title neovide ignores 'alt+' codes on Winsows neovide ignores 'alt+' codes on Windows Mar 28, 2024
@fredizzimo
Copy link
Member

That's very tricky to implement, due to the fact that someone might want to map alt-0 for example to something, so we have to send the key to Neovim as soon as it happens.

But you can use this instead:
https://neovim.io/doc/user/insert.html#i_CTRL-V_digit

If you type something often, you could also possibly use abbreviations:
https://neovim.io/doc/user/usr_24.html#24.7

@ZyX-II
Copy link
Contributor

ZyX-II commented Mar 28, 2024

I thought it possible to do that with a plugin, something like

function! s:AltMap(start)
    let nr = s:keys[a:start]
    let i = 0
    let extra = ""
    while 1
        let next = getchar(1)
        if next is# 0
            sleep 1m
            let i += 1
        elseif next is# 0x80
            " Note: getcharstr(1) for some reason only gets first byte which is 
            " 0x80. Thus may just as well use getchar() and not allocate 
            " a useless string.
            let s = getcharstr()
            if has_key(s:keys, s)
                let i = 0
                let nr = nr * 10 + s:keys[s]
            else
                break
            endif
        else
            break
        endif
    endwhile
    return nr2char(nr) . extra
endfunction

function! MakeMaps()
    unlockvar s:keys
    let s:keys = {}
    let v = 0
    let alts = ["Insert",
              \ "kEnd", "Down", "kPageDown",
              \ "Left", "kOrigin", "Right",
              \ "kHome", "Up", "kPageUp"]
    while v < 10
        for key in ["".v, alts[v]]
            let mkeyhrstr = "<M-" . key . ">"
            let mkeystr = eval('"\' . mkeyhrstr . '"')
            let s:keys[mkeystr] = v
            execute 'map <expr>' mkeyhrstr '<SID>AltMap('.string(mkeystr).')'
            execute 'map! <expr>' mkeyhrstr '<SID>AltMap('.string(mkeystr).')'
        endfor
        let v += 1
    endwhile
    lockvar! s:keys
endfunction

call MakeMaps()

After checking that I still think it is possible, but unfortunately, this specific code tends to fail due to getcharstr() often returning incomplete strings for some reason. One should be able to fix the issue with more complicated logic (something like “if s is a prefix of any key in s:keys use getcharstr() again, concatenate outputs and retry with that”), but I am not up to writing that now.

In any case, you can do this with a plugin, only if you are OK with character appearing either after timeout or after typing something else instead of after Alt release. Also plugin could not care whether or not you released Alt button while typing Alt+number sequence: button release events are not forwarded to neovim.

@ZyX-II
Copy link
Contributor

ZyX-II commented Mar 28, 2024

I am wondering though: if it is a common convention, should not there be either some option used on window creation (i.e. implemented by Windows itself) or, at least, winit option to not forward Alt+number events until release of Alt with neovide merely enabling/disabling it with some configuration option (at the cost of <A-N> mappings in this case)?

@fredizzimo fredizzimo added keyboard Input Catch all category for keyboard issues windows Specific to Windows and not investigable on other platforms labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working keyboard Input Catch all category for keyboard issues windows Specific to Windows and not investigable on other platforms
Projects
None yet
Development

No branches or pull requests

3 participants