LibWeb: Fix many bugs with the editing.

This commit is contained in:
asynts 2020-12-03 18:20:17 +01:00 committed by Andreas Kling
parent 78558c9f30
commit b3d7c5bfbc
2 changed files with 4 additions and 9 deletions

View file

@ -40,11 +40,6 @@ namespace Web {
void EditEventHandler::handle_delete(DOM::Range range)
{
// FIXME: Deleting nodes seems to mess up the layout tree. Not sure if this is not entirely
// my fault or not my fault at all.
dump_tree(*m_frame.document());
if (range.start().node() != range.end().node()) {
if (range.start().node()->parent() == range.end().node()->parent()) {
// Remove all intermediate nodes.
@ -85,8 +80,6 @@ void EditEventHandler::handle_delete(DOM::Range range)
// FIXME: We need to remove stale layout nodes when nodes are removed from the DOM. Currently,
// this is the only way to get these to disappear.
m_frame.document()->force_layout();
dump_tree(*m_frame.document());
}
void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)

View file

@ -346,12 +346,14 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
}
if (layout_root()->selection().is_valid()) {
auto range = layout_root()->selection().to_dom_range();
auto range = layout_root()->selection().to_dom_range().normalized();
m_frame.document()->layout_node()->set_selection({});
// FIXME: This doesn't work for some reason?
m_frame.set_cursor_position(range.start());
if (key == KeyCode::Key_Backspace) {
if (key == KeyCode::Key_Backspace || key == KeyCode::Key_Delete) {
if (range.start().node()->is_editable()) {
m_edit_event_handler->handle_delete(range);
return true;