diff options
author | asynts <asynts@gmail.com> | 2020-12-01 23:35:47 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-09 21:05:06 +0100 |
commit | bbcc5a93321fa34b537e5b635040357c4d49f5d6 (patch) | |
tree | e8644730e5ebfaba52196008883addc372d31598 /Libraries/LibWeb/Page/EventHandler.cpp | |
parent | 82aac98bea5bf69897e63df4f883470ed7cb3012 (diff) | |
download | serenity-bbcc5a93321fa34b537e5b635040357c4d49f5d6.zip |
LibWeb: Move editing stuff into EditEventHandler.
Diffstat (limited to 'Libraries/LibWeb/Page/EventHandler.cpp')
-rw-r--r-- | Libraries/LibWeb/Page/EventHandler.cpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 0f2ef8951f..3f50cbbd7f 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -52,6 +52,7 @@ static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, c EventHandler::EventHandler(Badge<Frame>, Frame& frame) : m_frame(frame) + , m_edit_event_handler(make<EditEventHandler>(frame)) { } @@ -344,34 +345,18 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin return focus_next_element(); } - if (m_frame.cursor_position().node() && m_frame.cursor_position().node()->is_editable()) { - // FIXME: Support backspacing across DOM node boundaries. - if (key == KeyCode::Key_Backspace && m_frame.cursor_position().offset() > 0) { - auto& text_node = downcast<DOM::Text>(*m_frame.cursor_position().node()); - StringBuilder builder; - builder.append(text_node.data().substring_view(0, m_frame.cursor_position().offset() - 1)); - builder.append(text_node.data().substring_view(m_frame.cursor_position().offset(), text_node.data().length() - m_frame.cursor_position().offset())); - text_node.set_data(builder.to_string()); - m_frame.set_cursor_position({ *m_frame.cursor_position().node(), m_frame.cursor_position().offset() - 1 }); - // FIXME: This should definitely use incremental layout invalidation instead! - text_node.document().force_layout(); + 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_frame.cursor_position().is_valid() && is<DOM::Text>(*m_frame.cursor_position().node())) { - auto& text_node = downcast<DOM::Text>(*m_frame.cursor_position().node()); - StringBuilder builder; - builder.append(text_node.data().substring_view(0, m_frame.cursor_position().offset())); - builder.append_code_point(code_point); - builder.append(text_node.data().substring_view(m_frame.cursor_position().offset(), text_node.data().length() - m_frame.cursor_position().offset())); - text_node.set_data(builder.to_string()); - // FIXME: This will advance the cursor incorrectly when inserting multiple whitespaces (DOM vs layout whitespace collapse difference.) - m_frame.set_cursor_position({ *m_frame.cursor_position().node(), m_frame.cursor_position().offset() + 1 }); - // FIXME: This should definitely use incremental layout invalidation instead! - text_node.document().force_layout(); + if (code_point) { + m_edit_event_handler->handle_insert(m_frame.cursor_position(), code_point); return true; } } + return false; } |