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

Don't panic if we get an unexpected key code #4576

Closed
wants to merge 1 commit into from

Conversation

groves
Copy link
Contributor

@groves groves commented Nov 3, 2022

It seems like we get media play/pause/mute/etc keys despite not emitting DISAMBIGUATE_ESCAPE_CODES(#4125).

Make crossterm::event::KeyCode a TryInto for KeyCode instead of Into to let us ignore keys we don't care about.

@groves groves mentioned this pull request Nov 3, 2022
It seems like we get media play/pause/mute/etc keys despite not
emitting DISAMBIGUATE_ESCAPE_CODES(helix-editor#4125).

Make crossterm::event::KeyCode a TryInto for KeyCode instead of Into to
let us ignore keys we don't care about.
@the-mikedavis the-mikedavis linked an issue Nov 4, 2022 that may be closed by this pull request
@@ -155,9 +157,9 @@ impl From<crossterm::event::KeyCode> for KeyCode {
| CKeyCode::Menu
| CKeyCode::KeypadBegin
| CKeyCode::Media(_)
| CKeyCode::Modifier(_) => unreachable!(
| CKeyCode::Modifier(_) => bail!(
"Shouldn't get this key without enabling DISAMBIGUATE_ESCAPE_CODES in crossterm"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Shouldn't get this key without enabling DISAMBIGUATE_ESCAPE_CODES in crossterm"
"Shouldn't get key {:?} without enabling DISAMBIGUATE_ESCAPE_CODES in crossterm",
val

Since the unreachable doesn't point at this line anymore, this should make it easier to debug if it shows up in the logfile

@archseer
Copy link
Member

archseer commented Nov 4, 2022

Rather than turning this into a try_from, why not add all these events to the internal event struct and properly handle them (or ignore them inside the editor)? That way we don't have to deal with intricacies of enabling DISAMBIGUATE_ESCAPE_CODES in a backwards-compatible way (i.e. not calling it on terminals with no support), but if we do get these events then they're at least handled.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. C-bug Category: This is a bug labels Nov 4, 2022
@archseer archseer added this to the 22.11 milestone Nov 17, 2022
@groves groves deleted the no-unknown-key-panic branch June 17, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on XF86 keycodes
4 participants