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

CMD + SHIFT works as CMD only #1237

Closed
goldcoders opened this issue Mar 4, 2022 · 44 comments · Fixed by #1899 or #2310
Closed

CMD + SHIFT works as CMD only #1237

goldcoders opened this issue Mar 4, 2022 · 44 comments · Fixed by #1899 or #2310
Labels
bug Something isn't working keyboard Input Catch all category for keyboard issues macos Specific to macOS and not investigable on other platforms

Comments

@goldcoders
Copy link

Ive enable CMD in neovide...

it works but i cant bind anything with SHIFT.

CTRL+SHIFT Works

also If i try to bind it is only registering the key as

this is not the case on other gui vim like VimR

@goldcoders goldcoders added the bug Something isn't working label Mar 4, 2022
@MultisampledNight
Copy link
Contributor

See #992 (comment).

@MultisampledNight
Copy link
Contributor

Partly closed by #1483. <S-{A,M,D,C}-* is implemented now, but <S-* is still to be done.

@fredizzimo
Copy link
Member

This should be fixed by #1899, it would be great if you can test that.

@mgax
Copy link
Contributor

mgax commented Jul 6, 2023

This should be fixed by #1899, it would be great if you can test that.

@fredizzimo It doesn't seem to be fixed in 340571b. On Mac OS, I have this pair of key bindings:

vim.keymap.set("n", "<D-]>", "gt")
vim.keymap.set("n", "<D-[>", "gT")

They get triggered when pressing either ⌘-[ or ⌘-shift-[. On the other hand, if I write them as follows, neither key combination will trigger them:

vim.keymap.set("n", "<D-S-]>", "gt")
vim.keymap.set("n", "<D-S-[>", "gT")

@mgax
Copy link
Contributor

mgax commented Jul 6, 2023

@MultisampledNight I don't think the bug is resolved, #1237 (comment) is still true.

@fredizzimo
Copy link
Member

fredizzimo commented Jul 6, 2023

I don't think that the issue that @mgax reported be fixed, unless we get a list of mapped keys from Neovim itself and choose which one of the mappings should be used.

Otherwise, we need to know if pressing shift contributed to the character or not, and that's not some information we have. Currently we always assume that it contributes to it.

There are two conditions where you should be able to map cmd+shift though, and I think these two cases work.

  1. In combination with keys that don't produce characters, like the F-keys, space, enter and so on.
  2. If cmd and cmd+shift produces different characters, you can map both characters separately, but excluding the shift key itself.

Edit: I realized that there's another way of resolving it, but that has to be an option. Some users have requested the ability to use the base virtual keycode in the mappings #1899 (comment), without any kind of translation to the language actually used. In that case you would always have to use the base character + all modifiers for your mappings. But this is not supported by winit at the moment either.

@mgax
Copy link
Contributor

mgax commented Jul 6, 2023

If cmd and cmd+shift produces different characters, you can map both characters separately, but excluding the shift key itself.

Would this work for <D-]> vs <D-}>? In a quick test, the first is being triggered both for command-[ and command-shift-[, while the latter is never triggered.

Otherwise, we need to know if pressing shift contributed to the character or not, and that's not some information we have. Currently we always assume that it contributes to it.

Makes sense. FWIW I'm happy with the current implementation, and don't have a need to distinguish between shift and no-shift key bidings, because my muscle memory is command-s to save the file, and command-shift-[ to switch to the previous tab, and both work, even if the key binding is slightly different than what I type.

@fredizzimo
Copy link
Member

Would this work for <D-]> vs <D-}>

Yes, it should, but we probably need rust-windowing/winit#2887.

On other plarforms we are able to do similar mappings.

@fredizzimo
Copy link
Member

It seems like winit might not be reporting the shifted character at all in combination with CMD. If that's the case we should report it to the Winit team, since all other platforms does that, and it would be better if it's consistent. As a last resort the following code could be modified to not strip out shift (and probably not alt either) if CMD is held on macOS

pub fn format_modifier_string(&self, is_special: bool) -> String {
// Is special is used for special keys so that all modifiers are always included
// It's also true with alt_is_meta is set to true.
// When the key is not special, shift is removed, since the base character is already
// shifted. Furthermore on macOS, meta is additionally removed when alt_is_meta is set to false
let shift = or_empty(self.modifiers.state().shift_key() && is_special, "S-");
let ctrl = or_empty(self.modifiers.state().control_key(), "C-");
let alt = or_empty(
self.modifiers.state().alt_key() && (use_alt() || is_special),
"M-",
);
let logo = or_empty(self.modifiers.state().super_key(), "D-");
shift.to_owned() + ctrl + alt + logo
}
}

@technicalpickles
Copy link

Can someone confirm I am understanding this problem correctly? To map to, say, command-shift-p:

  • <D-S-p> does not work currently
  • <D-P> should work

This doesn't seem to work for me. I've tried the same mapping, except with control, and the same result:

  • <C-P>
  • <C-S-p>
  • <C-S-P>

I'm currently on de22d0c

@fredizzimo
Copy link
Member

fredizzimo commented Aug 1, 2023

@technicalpickles, <D-P> and <C-P> are the correct mappings, that's how it works on both Linux and Windows.

I suspect that the problem is that keyevent.text is p instead of P in the code below, and that's IMO a winit bug. But someone with a mac need to debug further to confirm that so that the bug can be properly reported upstream.

key_event
.text
.as_ref()
.or(match &key_event.logical_key {
Key::Character(text) => Some(text),
_ => None,
})
.map(|text| self.format_key_text(text.as_str(), false))

Another possibility is that it takes the following branch, even if alt/meta is not pressed.

#[cfg(target_os = "macos")]
if self.modifiers.state().alt_key() && use_alt() {
return key_event
.key_without_modifiers()
.to_text()
.map(|text| self.format_key_text(text, true));

@mgax
Copy link
Contributor

mgax commented Aug 1, 2023

I suspect that the problem is that keyevent.text is p instead of P in the code below

I can confirm, both command-r and command-shift-r are returned as Some("<D-r>") by format_normal_key.

Another possibility is that it takes the following branch, even if alt/meta is not pressed.

Nope, a println! in that branch doesn't print anything.

@fredizzimo
Copy link
Member

It looks like it's more complex than I thought, the other platforms are actually not working correctly either in all cases. Nvim itself treats <C-a> and <C-A> the same, but <C-S-a> differently. In that case we don't need more information from winit, and can fix it ourselves.

For some reason I also can't get any number keys plus control to work on Windows, that's this bug rust-windowing/winit#2898, I thought I tested it before and it worked for almost all numbers, but maybe I only did on Linux.

So I think I need to re-think the control and cmd mappings completely.

@fredizzimo
Copy link
Member

Could someone do some testing in combination with #1962, and attach the log here?

That should give us more information to report the bug to Winit, and possibly about a workaround on the Neovide side.

It would be good to test with both CMD and CTRL combinations since both appears to be broken based on the comments here.

Note that I was wrong about the mapping of CTRL. for CTRL+SHIFT+alpha mappings. You should always include SHIFT like this for example <C-S-A>. This is a limitation of Neovim itself, and only applies to regular alpha keys, combined with CTRL. All other mappings should be mapped without shift, including the CMD ones.

@technicalpickles
Copy link

I just tested the branch with neovide --log. Here's the log from <D-p>:

TRACE [neovide::window::keyboard_manager] Key pressed <D-p> ModifiersState(SUPER)
TRACE [neovide::channel_utils] neovide::bridge::ui_commands::UiCommand Serial(Keyboard("<D-p>"))

And <D-P>:

TRACE [neovide::window::keyboard_manager] Key pressed <D-p> ModifiersState(SHIFT | SUPER)
TRACE [neovide::channel_utils] neovide::bridge::ui_commands::UiCommand Serial(Keyboard("<D-p>"))

@fredizzimo
Copy link
Member

I also got another log

TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: SuperLeft,
    logical_key: Super,
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Super,
    },
}
TRACE [neovide::redraw_scheduler] Next frame queued
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: ShiftLeft,
    logical_key: Shift,
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Shift,
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT | SUPER), pressed_mods: ModifiersKeys(LSHIFT | LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: KeyD,
    logical_key: Character(
        "d",
    ),
    text: Some(
        "d",
    ),
    location: Standard,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "d",
        ),
        key_without_modifiers: Character(
            "d",
        ),
    },
}

I think that's enough I need to report the bug to the Winit team But @technicalpickles also reported that Ctrl+shift does not work, so I think it would be good to get a a similar log with that as well before reporting.

We do have enough information to work around the bug, if we send <D-S-d> to Neovim, I think it would interpret it correctly, but I would rather see a proper fix in Winit.

@skanev
Copy link

skanev commented Aug 25, 2023

This commit fixes it. Happy to open a PR, although the fix is a bit tactical and I'm not sure if you'll accept it (good enough for me until this gets resolved upstream).

skanev@e2e9031

The problem is, I think, just the logic in KeyboardManager.format_modifier_string which clearly doesn't add the S- in some cases where it should.

@fredizzimo
Copy link
Member

The problem is, I think, just the logic in KeyboardManager.format_modifier_string which clearly doesn't add the S- in some cases where it should.

No that's not the problem, but it's the last resort workaround we have. We should get the shifted character from winit, like we do in combination with other modifiers and on other platforms than macOS.

Otherwise, it will only work for alpha keys, Neovim has no idea what a shifted number means for example.

Before this workaround gets accepted, we should report the issue upstream and get at least a response from them that it's not possible to do. If someone wants to do that, feel free to do so, but personally I am waiting to get logs for the C-S case as well, so that can be reported at the same time. The logging can now be done on master, and I need a similar log as the one I posted a couple of messages above this.

@technicalpickles wrote that C-S combinations are not working either here #1237 (comment)

@fredizzimo
Copy link
Member

Another reason why the patch is problematic is that with the fix you have to map like this <D-S-a>, but if the issue is fixed upstream, then Neovide starts to send <D-S-A> which are not the same, only ctrl mappings are special cased in Neovim.

@skanev
Copy link

skanev commented Aug 25, 2023

No that's not the problem, but it's the last resort workaround we have. We should get the shifted character from winit, like we do in combination with other modifiers and on other platforms than macOS.

Ah, I beg to differ.

First, when it comes to the command key, there isn't a right answer actually. Since there is no official spec, let's just take a look what the popular macOS (n)vim GUIs do on cmd+shift+f

  • MacVim reports <D-F>
  • VimR reports <S-D-f>
  • nvim-qt reports <S-D-F>
  • neovide used to report <S-D-f>, now it reports just <D-f>

(curiously, we have all the combinations now)

I'd take any of the first three, and since I'm trying to maintain most popular GUIs working on most OSes, I'm actually handling all of them in my config. It's a bit messy, I know, apologies :)

It could be argued that <D-F> makes the most sense, but honestly, I think any will do. If it was up to me, I'd definitely take <S-D-f> now and change to <D-F> (or <S-D-F>) later, over having to build from source until it gets fixed in the most correct way some time in the future.

I'd also like to point out that a <C-S> mapping should be triggered on ctrl+s and not necessarily ctrl+shift+s. (Neo)Vim has terminal-first vibes, and there is no universal way to send ctrl+shift+s to the terminal. I mean, there is libtermkey and whatever it turned to these days, and it also needs to be supported by the terminal emulator, but my point is that mapping <C-S> should be always triggered on ctrl+s in Neovide or any GUI, because that's how terminal Vim works as well.

@fredizzimo
Copy link
Member

fredizzimo commented Aug 25, 2023

MacVim is correct and that’s what Neovide should send too unless it’s impossible. Neovim-qt also sends an acceptable code, and for ascii characters, I’m pretty sure both of those mappings can be used interchangeably in Neovim.

So we should report the bug upstream, so that we are able to send the same, before making any workarounds. And I will do that, as soon as I have all the required information to do so.

C-S is special due to legacy reasons, and is the same as C-s. You can’t even map both at the same time in Neovim, they overwrite each other. But C-S-S is unique and should trigger on on ctrl+shift+s.

This is documented in intro.txt, but only for CTRL

CTRL-{char} {char} typed as a control character; that is, typing {char}
while holding the CTRL key down. The case of {char} is
ignored; thus CTRL-A and CTRL-a are equivalent. But in
some terminals and environments, using the SHIFT key will
produce a distinct code (e.g. CTRL-SHIFT-a); in these
environments using the SHIFT key will not trigger commands
such as CTRL-A

Alt is documented this way and other modifiers should follow the same convention

For a readable mapping command the <A-k> form can be used. Note that <A-k>
and <A-K> are different, the latter will use an upper case letter. Actually,
<A-K> and <A-S-K> are the same. Instead of "A" you can use "M". If you have
an actual Meta modifier key, please see :map-meta-keys.

So, <S-D-f> is very wrong.

@skanev
Copy link

skanev commented Aug 28, 2023

Well, fair enough.

Is it reasonable to ask, though, that unless this is fixed in winit for the next Neovide release, we get the very wrong solution instead of the no solution?

Apart from that, since I have a Mac, and would love not to have to build Neovide from source, I'm very happy to do whatever you need in order to report/fix/test the wininit issue. I would just need some instructions on what to do.

@fredizzimo
Copy link
Member

Is it reasonable to ask, though, that unless this is fixed in winit for the next Neovide release, we get the very wrong solution instead of the no solution?

Yes, if we for some reason don't get a response from the Winit team or if it's more difficult than expected for them to fix, then we can look at alternative solutions.

Apart from that, since I have a Mac, and would love not to have to build Neovide from source, I'm very happy to do whatever you need in order to report/fix/test the wininit issue. I would just need some instructions on what to do.

Neovide main generates log events like this #1237 (comment), when you run it from main with neovide --log. That log is the relevant log lines for pressing cmd+shift+d. The text field should be Some("D") instead of Some("d"). In the log file you can also see that it correctly detected that both super and shift were pressed. If you press just shift+d then the text is correctly reported as Some("D"). The logs contain much more than that, but I only need the two modifier events and the actual character event.

Since it was reported that other modifiers behave the same way, I need similar logs for other modifiers, ctrl for example in combination with shift, so that all of it can be reported and fixed at the same time. And so that we also can report what works and what doesn't work.

Note that for Meta/Option, it's possible that there's a bug on our side, since we use our own implementation rather than the Winit provided OptionAsAlt (which for some reason does not show up in the documentation) but was added here rust-windowing/winit#2887

@fredizzimo
Copy link
Member

I reported the issue here now rust-windowing/winit#3078 with incomplete information, please fill in any details there if needed.

@fredizzimo
Copy link
Member

If someone is able to help the Winit team debug and perhaps even fix the code, we can probably get this moving forward faster.

I guess you could start by compiling winit from source and adding logging here https://github.com/rust-windowing/winit/blob/master/src/platform_impl/macos/event.rs#L111.

If that does not give any results, then I guess we need to debug neovim-qt and/or MacVim, to see how they get the uppercase characters. I quickly tried to inspect the source code, but I didn't find anything special. But a debugger and/or logger should be able to reveal how.

@fredizzimo
Copy link
Member

I just reported a Neovim issue that is related neovim/neovim#25068 (but not the cause of this). It just makes it different to map things with CMD accross different GUIs. It would also make @skanev's workaround consistent, even if the bug in Winit is fixed.

I might actually go ahead and make a similar fix it as part of fixing this #2017 (comment). But if I go and do that, there might be another breaking change in the future when Winit is updated, if the Neovim issue is not also fixed before that.

@fredizzimo
Copy link
Member

fredizzimo commented Sep 9, 2023

Since there was another keyboard issue, which will require extensive testing, I combined it with a partial fix for this issue in this PR #2018. The advantage of the solution I chose is that it will continue working, even if it's actually gets fixed in Winit later on, without breaking user mapping, and it then also works correctly with non-alpha mappings.

So please, test it if you can. You should always use the form <D-A>, for the mappings, so don't include any <S-> anywhere.

NOTE: The reason why I think it's only partially working is that it likely does not work with special characters and non-ascii characters like Ä. But I might be wrong.

@skanev
Copy link

skanev commented Sep 13, 2023

Tested on mac, <D-d> and <D-D> work correctly.

cmd+shift+8 produces <D-8> which is indistinguishable from the shift-less version, but I'd take this change gladly :)

@fredizzimo
Copy link
Member

@fredizzimo
Copy link
Member

The winit fix is now merged

So, once a new release is made and we update, we should finally be able to completely close this issue.

@fredizzimo fredizzimo added keyboard Input Catch all category for keyboard issues macos Specific to macOS and not investigable on other platforms labels Jan 13, 2024
@fredizzimo
Copy link
Member

#2310, will finally close this.

@lttb
Copy link

lttb commented Jan 26, 2024

@fredizzimo thanks for your amazing work! I've tried neovide with winit 0.29.10 on macos, and for some reason, cmd+shift keymaps still don't work.
is there anything else required besides the dependency update?

@fredizzimo
Copy link
Member

Hm. this was merged and should be included, but I don't have a macOS computer myself, so I'm unable to test

Maybe we also need to do something?

@fredizzimo
Copy link
Member

@lttb, are you able to provide a log file neovide --log from that PR? So that I can see what keypresses gets reported to Neovide.

@lttb
Copy link

lttb commented Jan 26, 2024

@fredizzimo please let me know if I need to share more logs or data

example of logs pressing `cmd+shift+f` (it seems it doesn't register S-D-f in neovim)
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        ShiftLeft,
    ),
    logical_key: Named(
        Shift,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Shift,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT), pressed_mods: ModifiersKeys(LSHIFT) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        SuperLeft,
    ),
    logical_key: Named(
        Super,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Super,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT | SUPER), pressed_mods: ModifiersKeys(LSHIFT | LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        KeyF,
    ),
    logical_key: Character(
        "F",
    ),
    text: Some(
        "F",
    ),
    location: Standard,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "f",
        ),
        key_without_modifiers: Character(
            "f",
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Key pressed <D-F> ModifiersState(SHIFT | SUPER)
TRACE [neovide::channel_utils] UICommand Serial(Keyboard("<D-F>"))
TRACE [neovide::bridge::ui_commands] In Serial Command
TRACE [neovide::bridge::ui_commands] Keyboard Input Sent: <D-F>
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        KeyF,
    ),
    logical_key: Character(
        "F",
    ),
    text: None,
    location: Standard,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "f",
        ),
        key_without_modifiers: Character(
            "f",
        ),
    },
}
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        ShiftLeft,
    ),
    logical_key: Named(
        Shift,
    ),
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Shift,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SUPER), pressed_mods: ModifiersKeys(LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        SuperLeft,
    ),
    logical_key: Named(
        Super,
    ),
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Super,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(0x0), pressed_mods: ModifiersKeys(0x0) }
example of logs pressing `opt+shift+f` (registers S-M-f as expected)
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        ShiftLeft,
    ),
    logical_key: Named(
        Shift,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Shift,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT), pressed_mods: ModifiersKeys(LSHIFT) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        AltLeft,
    ),
    logical_key: Named(
        Alt,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Alt,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT | ALT), pressed_mods: ModifiersKeys(LSHIFT | LALT) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        KeyF,
    ),
    logical_key: Character(
        "Ï",
    ),
    text: Some(
        "Ï",
    ),
    location: Standard,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "Ï",
        ),
        key_without_modifiers: Character(
            "f",
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Key pressed <S-M-F> ModifiersState(SHIFT | ALT)
TRACE [neovide::channel_utils] UICommand Serial(Keyboard("<S-M-F>"))
TRACE [neovide::bridge::ui_commands] In Serial Command
TRACE [neovide::bridge::ui_commands] Keyboard Input Sent: <S-M-F>

@fredizzimo
Copy link
Member

fredizzimo commented Jan 26, 2024

Did you map it as <D-F>? Notice the uppercase F

@lttb
Copy link

lttb commented Jan 26, 2024

right, that was it! I mapped it as <D-S-f>, but <D-F> works great. although it looks like <D-F> doesn't work in kitty's keyboard protocol or kitty

@fredizzimo
Copy link
Member

Actually I think <D-F> was already working before the winit fix, but now special characters should additionally work, like stuff on the numbers row.

For the reason why <D-S-f> does not work, see #1237 (comment), we made it work the same way as alt, instead of CTRL

@lttb
Copy link

lttb commented Jan 26, 2024

I see, thank you for clarifying!
anyway, I can confirm now that combinations with cmd work as expected.
and I've recompiled neovide with winit v0.29.4, and you are right, it was working before too, it was just the mapping declaration issue.

do you think it makes sense to add these mapping details to https://neovide.dev/troubleshooting.html or https://neovide.dev/faq.html for example? I guess people coming from kitty might experience such issues, and probably some guidance there might help

@fredizzimo
Copy link
Member

Yes, I think we need some documentation, I will check that after the release I'm preparing is out.

@lttb
Copy link

lttb commented Jan 26, 2024

out of curiosity, should <M-D-F> work too? I've noticed that cmd+opt+shift+f actually sends <S-M-D-F> in neovide, is it expected?

logs
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        ShiftLeft,
    ),
    logical_key: Named(
        Shift,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Shift,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT), pressed_mods: ModifiersKeys(LSHIFT) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        AltLeft,
    ),
    logical_key: Named(
        Alt,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Alt,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT | ALT), pressed_mods: ModifiersKeys(LSHIFT | LALT) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        SuperLeft,
    ),
    logical_key: Named(
        Super,
    ),
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Super,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SHIFT | ALT | SUPER), pressed_mods: ModifiersKeys(LSHIFT | LALT | LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        KeyF,
    ),
    logical_key: Character(
        "Ï",
    ),
    text: Some(
        "Ï",
    ),
    location: Standard,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "Ï",
        ),
        key_without_modifiers: Character(
            "f",
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Key pressed <S-M-D-F> ModifiersState(SHIFT | ALT | SUPER)
TRACE [neovide::channel_utils] UICommand Serial(Keyboard("<S-M-D-F>"))
TRACE [neovide::bridge::ui_commands] In Serial Command
TRACE [neovide::bridge::ui_commands] Requesting nvim version
TRACE [neovide::bridge::ui_commands] actual nvim version: 0.10
TRACE [neovide::bridge::ui_commands] expect nvim version: 0.10
TRACE [neovide::bridge::ui_commands] has desired nvim version: true
TRACE [neovide::bridge::ui_commands] Keyboard Input Sent: <S-M-D-F>
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        KeyF,
    ),
    logical_key: Character(
        "Ï",
    ),
    text: None,
    location: Standard,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: Some(
            "Ï",
        ),
        key_without_modifiers: Character(
            "f",
        ),
    },
}
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        ShiftLeft,
    ),
    logical_key: Named(
        Shift,
    ),
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Shift,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(ALT | SUPER), pressed_mods: ModifiersKeys(LALT | LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        AltLeft,
    ),
    logical_key: Named(
        Alt,
    ),
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Alt,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(SUPER), pressed_mods: ModifiersKeys(LSUPER) }
TRACE [neovide::window::keyboard_manager] KeyEvent {
    physical_key: Code(
        SuperLeft,
    ),
    logical_key: Named(
        Super,
    ),
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifiers: None,
        key_without_modifiers: Named(
            Super,
        ),
    },
}
TRACE [neovide::window::keyboard_manager] Modifiers { state: ModifiersState(0x0), pressed_mods: ModifiersKeys(0x0) }

@fredizzimo
Copy link
Member

I think that's a bug actually. But I think it's fixed in

Unfortunately, that PR has stalled, though, so I think someone else needs to take over. And it can actually be cleaned up quite much now, when we have added support for options listeners.

@fredizzimo
Copy link
Member

Neovim 0.10 should now accept <D-S-f> and <D-S-F> in addition to the normalized <D-F>. But I still recommend using the normalized form, since that works with special characters and numbers as well.

@codeitlikemiley
Copy link

codeitlikemiley commented Apr 8, 2024

I can verify on my mac

nvim --version
NVIM v0.10.0-dev-2836+g2528093bb-Homebrew
Build type: Release
LuaJIT 2.1.1710088188
Run "nvim -V1 -v" for more info

that when i run neovide with this neovim config

rust-tools.lua
local cargo_run = require("utils/cargo_run")
local cargo_bin = require("utils/cargo_bin")

function RustToggleInlayHints()
  if vim.g.rust_inlay_hints_enabled then
    vim.cmd("RustDisableInlayHints")
    vim.g.rust_inlay_hints_enabled = false
  else
    vim.cmd("RustEnableInlayHints")
    vim.g.rust_inlay_hints_enabled = true
  end
end

vim.g.rust_inlay_hints_enabled = true

local custom_attach = function(_, bufnr)
  if vim.fn.has("macunix") == 1 and vim.fn.exists("neovide") == 1 then

    -- MacOS Keymaps
    vim.keymap.set("n", "<D-S-R", RustToggleInlayHints, { silent = true, desc = "Rust Toggle Inlay Hints" })
    vim.keymap.set("n", "<D-i>", RustToggleInlayHints, { silent = true, desc = "Rust Toggle Inlay Hints" })
    vim.keymap.set("n", "<D-m>", ":RustExpandMacro<CR>", { silent = true, desc = "Expand Rust Macro" })
    vim.keymap.set("n", "<D-y>", ":RustParentModule<CR>", { silent = true, desc = "Rust Parent Module" })
  elseif
      vim.fn.has("unix") == 1 and vim.fn.exists("neovide") == 1
      or vim.fn.has("win32") and vim.fn.exists("neovide") == 1
  then
    -- Windows and Linux Keymaps
    vim.keymap.set("n", "<M-r>", cargo_run, { silent = true, desc = "Rust Run App" })
    vim.keymap.set("n", "<M-w>", cargo_bin, { silent = true, desc = "Run All your Installed Cargo Commands" })
    vim.keymap.set("n", "<M-y>", ":RustParentModule<CR>", { silent = true, desc = "Rust Parent Module" })
    vim.keymap.set("n", "<M-i>", ":RustToggleInlayHints<CR>", { silent = true, desc = "Rust Toggle Inlay Hints" })
    vim.keymap.set("n", "<M-m>", ":RustExpandMacro<CR>", { silent = true, desc = "Expand Rust Macro" })
  end
  -- Universal Keymaps

  -- Function keys
  vim.keymap.set("n", "<F1>", ":RustRunnables<CR>", { silent = true, desc = "Rust Runnables" })
  vim.keymap.set("n", "<F3>", ":RustDebuggables<CR>", { silent = true, desc = "Rust Debuggables" })
  vim.keymap.set("n", "<M-r>", cargo_bin, { silent = true, desc = "Execute Cargo Bin" })
  vim.keymap.set("n", "<F5>", ":RustReloadWorkspace<CR>", { silent = true, desc = "Reload Rust Workspace" })


  vim.keymap.set("n", "<leader>rt", ':lua require("neotest").run.run()<CR>', { silent = true, desc = "Cargo Test" })
  vim.keymap.set("n", "<leader>rr", ":RustRunnables<CR>", { silent = true, desc = "Rust Runnables" })
  vim.keymap.set(
    "n",
    "<leader>rl",
    ':lua require("neotest").summary.toggle()<CR>',
    { silent = true, desc = "Test Summary" }
  )

  vim.keymap.set("n", "<leader>rb", cargo_bin, { silent = true, desc = "Run All your Installed Cargo Commands" })
  vim.keymap.set("n", "<leader>rd", ":RustDebuggables<CR>", { silent = true, desc = "Rust Debuggables" })
  vim.keymap.set("n", "<leader>rn", cargo_run, { silent = true, desc = "Cargo Run" })
  vim.keymap.set("n", "<leader>rm", ":RustExpandMacro<CR>", { silent = true, desc = "Expand Rust Macro" })
  vim.keymap.set("n", "<leader>rH", ":RustEnableInlayHints<CR>", { silent = true, desc = "Show Rust Inlay Hint" })
  vim.keymap.set("n", "<leader>rh", ":RustDisableInlayHints<CR>", { silent = true, desc = "Disable Rust Inlay Hint" })
  vim.keymap.set("n", "<leader>rf", ":!dx fmt<CR>", { silent = true, desc = "run Dioxus FMT" })
  vim.keymap.set(
    "n",
    "<leader>ru",
    ":lua require('dapui').toggle(); vim.cmd('Neotree position=right')<CR>",
    { noremap = true, silent = true, desc = "Toggle Debugger UI" }
  )
  vim.keymap.set(
    "n",
    "<leader>rs",
    ':execute "RustStartStandaloneServerForBuffer" | LspStop<CR>',
    { silent = true, desc = "Rust Standalone Server" }
  )
end
return custom_attach

That This Issue Still Persists

Current version of neovide im using

$HOME/.local/bin/neovide --version
neovide 0.12.2

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 macos Specific to macOS and not investigable on other platforms
Projects
None yet
8 participants