1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

LibWeb: Add support for range deletion.

This commit is contained in:
asynts 2020-12-01 23:36:12 +01:00 committed by Andreas Kling
parent bbcc5a9332
commit 43dc47a494
8 changed files with 107 additions and 6 deletions

View file

@ -345,16 +345,33 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
return focus_next_element();
}
if (layout_root()->selection().is_valid()) {
auto range = layout_root()->selection().to_dom_range();
if (key == KeyCode::Key_Backspace) {
if (range.start().node()->is_editable()) {
m_edit_event_handler->handle_delete(range);
return true;
}
}
// FIXME: Check if this code point is in the printable character range.
m_edit_event_handler->handle_delete(range);
m_edit_event_handler->handle_insert(m_frame.cursor_position(), code_point);
return true;
}
if (m_frame.cursor_position().is_valid() && m_frame.cursor_position().node()->is_editable()) {
if (key == KeyCode::Key_Backspace) {
m_edit_event_handler->handle_delete(m_frame.cursor_position());
return true;
}
if (code_point) {
m_edit_event_handler->handle_insert(m_frame.cursor_position(), code_point);
return true;
}
// FIXME: Check if this code point is in the printable character range.
m_edit_event_handler->handle_insert(m_frame.cursor_position(), code_point);
return true;
}
return false;