Просмотр исходного кода

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`).
Aliaksandr Kalenik 1 год назад
Родитель
Сommit
6b17ab77f3
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      Userland/Libraries/LibWeb/Page/EventHandler.cpp

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

@@ -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?