mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 05:38:15 +00:00
LibWeb: Add very basic backspace support to content editing
This commit is contained in:
parent
bc299754f6
commit
8b16c61ff8
1 changed files with 15 additions and 2 deletions
|
@ -229,8 +229,21 @@ void EventHandler::dump_selection(const char* event_name) const
|
||||||
#endif
|
#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())) {
|
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());
|
auto& text_node = downcast<DOM::Text>(*m_frame.cursor_position().node());
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -244,7 +257,7 @@ bool EventHandler::handle_keydown(KeyCode, unsigned, u32 code_point)
|
||||||
text_node.document().force_layout();
|
text_node.document().force_layout();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue