mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +00:00
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
This commit is contained in:
parent
0d3072bdac
commit
d73979e0a8
1 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue