question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keyboard layout changes to wrong layout during usage

See original GitHub issue

Description

https://user-images.githubusercontent.com/46352445/134766193-97266791-32df-4206-a94d-889fd194fdf2.mp4

Finnish keyboard layout: http://kbdlayout.info/KBDFI/

So initially the layout is all good. As you can see, I can type multiple “-” (next to right-shift) on my Finnish keyboard. But when I “submit” the answer the next time I’m using mathfield the layout has changed to a wrong layout, where pressing the same key leads it to be interpreted as “/” which leads to a fraction.

About that “submit”. Copy-pasting all my code to codesandbox would take a bit too much time I try to explain the part of code that I think is relevant to this issue. I could share @arnog my private repo for a moment to debug this if you think that’s needed.

  const handleOnEnterKeyPressedOrFocusLostAndValueChanged = () => {
    if (mfe.value !== "") {
      // This is a long function (that comes from parent component) that get's called when I "submit" the answer
     // Eg. Checking the answer, clearing states, showing the success message etc.
      onEnterKeyPressedOrFocusLostAndValueChanged(mfe.getValue(format))
      mfe.setValue("")
    }
  }

  useLayoutEffect(() => {
    console.log("Mounting mathfield")

    ref.current?.appendChild(mfe)
    mfe.addEventListener(
      "change",
      handleOnEnterKeyPressedOrFocusLostAndValueChanged
    )
    mfe.focus()
    return () => {
      console.log("Unmounting mathfield")

      mfe.removeEventListener(
        "change",
        handleOnEnterKeyPressedOrFocusLostAndValueChanged
      )
      ref.current?.removeChild(mfe)
    }
  }, [])

Steps to Reproduce

  1. I start using mathfield and it’s working
  2. As long as I don’t press “-” everything works as intended
  3. When I at some point of time press “-”, the next math challenge I try to type “-” is interpreted as a fraction

Actual Behavior

I can’t type “-”

Expected Behavior

I can type “-”

Environment

MathLive version

0.69.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:28 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
1lyadcommented, Oct 11, 2021

Had same issue with swedish layout, fixed it with “locale=sv-SE”

1reaction
tkainradcommented, Sep 30, 2021

Thansk for the mentin @Temez1. This was a very interesting read for me, as I have come to similar conclusions as @arnog over the past two years. Would have been very helpful to read these comments before that time.

Unfortunately, I don’t have much to add to the discussion. @stefnotch already mentions Keyboard.getLayoutMap(), which can be used to get a mapping from a key’s universal code to the layout-dependent character that’s printed on the user’s keyboard. KeyCombiner uses this to display a layout-specific virtual keyboard for each user. However, the API is only available on Chromium-based browsers and has other problems, too.

In my experience, letting users define their own bindings is the only approach that kinda solves this problem for every possible layout and special case. They can just assign what works for them on their machine. Other approaches that I mentioned in my article (using keypress, the event’s key property,…) could work well for simple apps, but make it very complicated when trying to provide support for many special characters, like I think MathLive is doing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 keyboard layout change error
Click Start and type "troubleshoot" then select the first result. Scroll down and choose Keyboard. Run the troubleshooter and it might fix the ......
Read more >
How to avoid keyboard layout automatically changing on ...
Go to Control Panel\Clock, Language and Region\Language\Advanced settings\Change Language Bar hotkeys; In the "Advanced Key Settings" tab, ...
Read more >
Wrong Keyboard layout - reverts to US Eng Layout after restart
I have to reset it manually using the ENG in the task bar by the notification area. This of course then reverts when...
Read more >
How to change keyboard layout on Windows 10
Windows 10 asks you to configure additional keyboard layouts during the initial setup. However, you can always add or remove layouts if you ......
Read more >
Windows 10 keeps changing keyboard layout fix. - YouTube
Windows 10 keeps changing keyboard layout is very annoying. In this tutorial I am going to try to help You with this language...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found