summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Page/EventHandler.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-02 15:53:31 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-02 17:34:50 +0200
commit8b16c61ff879d24e9dc32881ba5bb608f6a35502 (patch)
treec8fcea9ac5de3c9cf8975cf8a9de4a9e4360fd54 /Libraries/LibWeb/Page/EventHandler.cpp
parentbc299754f648d89d901824472b54d73b6ce6e3ed (diff)
downloadserenity-8b16c61ff879d24e9dc32881ba5bb608f6a35502.zip
LibWeb: Add very basic backspace support to content editing
Diffstat (limited to 'Libraries/LibWeb/Page/EventHandler.cpp')
-rw-r--r--Libraries/LibWeb/Page/EventHandler.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 9a25bd3a32..bf03ab46e3 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -229,8 +229,21 @@ void EventHandler::dump_selection(const char* event_name) const
#endif
}
-bool EventHandler::handle_keydown(KeyCode, unsigned, u32 code_point)
+bool EventHandler::handle_keydown(KeyCode key, unsigned, u32 code_point)
{
+ // 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();
+ 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;
@@ -244,7 +257,7 @@ bool EventHandler::handle_keydown(KeyCode, unsigned, u32 code_point)
text_node.document().force_layout();
return true;
}
- return true;
+ return false;
}
}