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

Dead keys not being handled #1094

Closed
Andrepuel opened this issue Sep 8, 2022 · 19 comments
Closed

Dead keys not being handled #1094

Andrepuel opened this issue Sep 8, 2022 · 19 comments
Labels
A-keymap Area: default key bindings C-bug Category: bug - something isn't working as it's supposed to
Milestone

Comments

@Andrepuel
Copy link

Lapce Version

0.2.0

System information

Arch linux

Describe the bug

The key related to key code 48 is not being handled by text editor. It is also not being handled by builtin terminal.

The number 48 was extracted using the command "xinput test":

key press 48
key release 48

Additional information

In the keybindings settings dialog, when I press 48, I get the name "Dead" for the key:
image

If I assign the key 48 to the command palette command, when I press the key 48, the command palette does open.

Remarks: On my keyboard, which is english qwerty layout, key code 48 refers to double quote / single quote.

@MinusGix MinusGix added C-bug Category: bug - something isn't working as it's supposed to A-keymap Area: default key bindings labels Sep 9, 2022
@Andrepuel Andrepuel changed the title Key code 48 not being handled Dead keys not being handled Sep 9, 2022
@Andrepuel
Copy link
Author

Upon further investigation I understand now that the problem is lack of dead keys handling. If a dead key is pressed, nothing happens. Nothing specific about "key code 48" but it being a dead key on my keymap.

Workaround: to change the keymap to a layout without dead keys.

Related issue: #530

@Andrepuel
Copy link
Author

More information, this seems to be related to the feature of dead key preview:

https://gitlab.gnome.org/GNOME/gtk/-/issues/3815

@llp-devr
Copy link

I have the same problem on MacOS with US keyboard + Dead Keys.

@luluco250
Copy link

I have the same issue on Arch Linux with an US keyboard set to US intl.

It does seem like the editor is simply not handling dead keys at all, they don't even enter the characters on the key.

@Guillermogsjc
Copy link

Guillermogsjc commented Oct 17, 2022

here with Lapce v0.2.1 over 5.19.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.11-1 (2022-09-24) x86_64 GNU/Linux hitting same issue with key ` with spanish layout

@jsanta
Copy link

jsanta commented Jan 19, 2023

Same here. Happening with single and double quotes, and tilde and backtick.
I'm currently using a 66% keyboard configured as En(intl)+deadkeys .

Love the idea of using Lapce as my main code editor, but it's plainly useless without the capability of typing a single or double quote.

@fabiopetrillo
Copy link

The issue is in the Druid UI toolkit. Lapce inherited this issue.

@lhsazevedo
Copy link

I'm experiencing the same issue here, which is unfortunate as I really liked the overall experience of Lapce...
I hope Druid UI fixes this in linebender/druid/issues/1040. Subscribing here to get notified.

@RivenSkaye
Copy link

Is Druid still being used in the nightly builds, or is some kind of changed handling in Floem victim to the same problem as the old codebase?

@panekj
Copy link
Collaborator

panekj commented Nov 27, 2023

Latest lapce release doesn't use Druid anymore, it's Floem and keyboard events are provided by Winit.

@RivenSkaye
Copy link

I was going to post an edit, but that was a surprisingly fast response.
A friend of mine that's much more knowledgeable about key handling than me is looking through Winit now and they're drawing the conclusion that Winit is breaking stuff here by calling ToUnicode a second time on dead keys. I'll try and see if this can be sorted on that end

@Random832
Copy link

Uh, false alarm there, the code I was looking at did call ToUnicodeEx, but turned out to be using it to inspect keyboard layouts rather than processing actual input. I haven't managed to find where the actual input processing is messed up (it appears to call TranslateMessage in the main loop, which should just work unless something else is calling ToUnicode somewhere)

@Random832
Copy link

Random832 commented Nov 28, 2023

ok, after installing lapce myself (i know, lazy), i observed the following:

  • contrary to my interpretation of reports, actual accented letters entered via the US-Intl layout dead keys on windows work fine
  • dead key + space enters nothingspace
  • dead key + other dead key enters nothing
  • dead key + letter with no corresponding accent enters only the letter.

All expected WM_CHAR messages do get generated (presumably by winit's call to TranslateMessage)
image
image

The above image is the event sequence from typing '''a'b, which results in only the text áb being typed in to the file [each on the respective letter keydown], not ''á'b as expected.

The WM_CHAR messages for the ' character do have the lparam flag 02000000 set, which may be an undocumented [other flags in this value are documented at https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keystroke-message-flags, 0x0200 is missing from this table] flag intended for this scenario, but the second one in the '' sequence and the one generated by '<space> does not have this set, but are still ignored.

@Random832
Copy link

I think I have finally figured out what is going on.

The keypress function

pub fn keypress<'a>(event: impl Into<EventRef<'a>>) -> Option<KeyPress> {
is discarding the text from the event, leaving its caller (key_down
pub fn key_down<'a, T: KeyPressFocus>(
) to infer characters from only the key being a Key::Character or NamedKey::Space (I am still unsure why this means it discards doubled dead keys or why accented characters work, but this is the only thing that can explain a space character being entered when a dead key is followed with the spacebar) The entire key_down function will have to be rewritten.

It is worth mentioning that (assuming that winit supports it correctly) KeyUp events can also have text, in the case of the event corresponding to Alt being released after entering an alt+numpad code. Other event handlers further up the chain may need to be reworked to accommodate this, if support for windows native alt+numpad codes is desired.

@Random832
Copy link

I have a basic fix that seems to work, replacing the contents of the if mods.is_empty() block with

            if let EventRef::Keyboard(keyevent) = event {
                if let Some(text) = &keyevent.key.text {
                    focus.receive_char(text.as_str());
                    self.count.set(None);
                    return true;
                }
            }

[and into-ing the event at the top of the function, since otherwise it can't be used both here and in the call to keypress], but I only have the ability to test it on Windows, and it also seems like a bit of a messy solution since fundamentally the problem is that the KeyPress type does not retain the text from the winit/floem keydown event, and I am not sure whether it should or not or even why this KeyPress type exists at all.

@fkellner
Copy link

Happens to me on Win11, too

@twelho
Copy link

twelho commented May 6, 2024

With Lapce v0.3.1 (Flatpak) dead keys seem to finally be working on my machine, both with and without IME running. When running IME, the phantom text is now also rendered.

@panekj
Copy link
Collaborator

panekj commented Jun 3, 2024

This should be fixed via #3119

@panekj panekj closed this as completed Jun 3, 2024
@panekj
Copy link
Collaborator

panekj commented Jun 3, 2024

Which is part of 0.4.0 so please test this and report any issues

@panekj panekj added this to the 0.4.0 milestone Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-keymap Area: default key bindings C-bug Category: bug - something isn't working as it's supposed to
Projects
None yet
Development

No branches or pull requests