1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

LibWeb: Do not delete empty range in EventHandler::handle_keydown()

Fixes a crash that occurs when inputting into an empty contenteditable
element (`EditEventHandler::handle_delete()` assumes the cursor
position's node is always `DOM::Text`, which is not the case for an
empty `contenteditable`).
This commit is contained in:
Aliaksandr Kalenik 2024-02-24 02:09:02 +01:00 committed by Andreas Kling
parent 1528e9109c
commit 6b17ab77f3

View file

@ -757,7 +757,7 @@ bool EventHandler::handle_keydown(KeyCode key, u32 modifiers, u32 code_point)
if (auto selection = document->get_selection()) {
auto range = selection->range();
if (range && range->start_container()->is_editable()) {
if (range && !range->collapsed() && range->start_container()->is_editable()) {
selection->remove_all_ranges();
// FIXME: This doesn't work for some reason?