Ladybird/Qt: Map Enter keypresses to the code point '\n'

Previously, on systems where pressing Enter would generate "\r\n", only
the '\r' character was being sent to the event handler. This change
ensures consistent behavior across platforms regardless of their native
line ending characters.
This commit is contained in:
Tim Ledbetter 2024-02-05 18:53:54 +00:00 committed by Tim Flynn
parent 5a8e82e6ea
commit 8320faf052
Notes: sideshowbarker 2024-07-17 00:37:23 +09:00

View file

@ -451,10 +451,16 @@ void WebContentView::keyPressEvent(QKeyEvent* event)
return;
}
auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
// This ensures consistent behavior between systems that treat Enter as '\n' and '\r\n'
client().async_key_down(m_client_state.page_index, KeyCode::Key_Return, modifiers, '\n');
return;
}
auto text = event->text();
auto point = text.isEmpty() ? 0u : event->text()[0].unicode();
auto keycode = get_keycode_from_qt_keyboard_event(*event);
auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
client().async_key_down(m_client_state.page_index, keycode, modifiers, point);
}