From d73979e0a84e68a38fc44f1c8abe991491e71880 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 30 Jan 2024 20:09:33 +0000 Subject: [PATCH] LibWeb: Don't update input text if Ctrl or Alt are pressed With this change, input elements ignore keypresses while Ctrl or Alt are pressed. This matches the behavior of Chrome and Firefox --- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 98016c2bfe..738c08ef13 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -689,10 +689,12 @@ bool EventHandler::focus_previous_element() return element; } -constexpr bool should_ignore_keydown_event(u32 code_point) +constexpr bool should_ignore_keydown_event(u32 code_point, u32 modifiers) { + if (modifiers & (KeyModifier::Mod_Ctrl | KeyModifier::Mod_Alt)) + return true; + // FIXME: There are probably also keys with non-zero code points that should be filtered out. - // FIXME: We should take the modifier keys into consideration somehow. This treats "Ctrl+C" as just "c". return code_point == 0 || code_point == 27; } @@ -755,7 +757,8 @@ bool EventHandler::handle_keydown(KeyCode key, u32 modifiers, u32 code_point) m_edit_event_handler->handle_delete(*range); return true; } - if (!should_ignore_keydown_event(code_point)) { + // FIXME: Text editing shortcut keys (copy/paste etc.) should be handled here. + if (!should_ignore_keydown_event(code_point, modifiers)) { m_edit_event_handler->handle_delete(*range); m_edit_event_handler->handle_insert(JS::NonnullGCPtr { *m_browsing_context->cursor_position() }, code_point); m_browsing_context->increment_cursor_position_offset(); @@ -818,7 +821,8 @@ bool EventHandler::handle_keydown(KeyCode key, u32 modifiers, u32 code_point) input_element.commit_pending_changes(); return true; } - if (!should_ignore_keydown_event(code_point)) { + // FIXME: Text editing shortcut keys (copy/paste etc.) should be handled here. + if (!should_ignore_keydown_event(code_point, modifiers)) { m_edit_event_handler->handle_insert(JS::NonnullGCPtr { *m_browsing_context->cursor_position() }, code_point); m_browsing_context->increment_cursor_position_offset(); return true;