Browse Source

LibWeb/EventHandler: Ignore repeated keyup events

Platforms such as X11 will typically send repeated keyRelease/keyup
events as a result of auto-repeating:

  * KeyPress (initial)
  * KeyRelease (repeat)
  * KeyPress (repeat)
  * KeyRelease (repeat)
  * ad infinitum

Make our EventHandler more spec-compliant by ignoring all repeated keyup
events. This fixes long-pressing the arrow keys on
https://playbiolab.com/.
Jelle Raaijmakers 8 months ago
parent
commit
77850b3540
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Userland/Libraries/LibWeb/Page/EventHandler.cpp

+ 6 - 1
Userland/Libraries/LibWeb/Page/EventHandler.cpp

@@ -1171,8 +1171,13 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, u
     return EventResult::Accepted;
 }
 
-EventResult EventHandler::handle_keyup(UIEvents::KeyCode key, u32 modifiers, u32 code_point, [[maybe_unused]] bool repeat)
+EventResult EventHandler::handle_keyup(UIEvents::KeyCode key, u32 modifiers, u32 code_point, bool repeat)
 {
+    // Keyup events as a result of auto-repeat are not fired.
+    // See: https://w3c.github.io/uievents/#events-keyboard-event-order
+    if (repeat)
+        return EventResult::Dropped;
+
     return fire_keyboard_event(UIEvents::EventNames::keyup, m_navigable, key, modifiers, code_point, false);
 }