mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Add very basic backspace support to content editing
This commit is contained in:
parent
bc299754f6
commit
8b16c61ff8
Notes:
sideshowbarker
2024-07-19 04:23:12 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8b16c61ff87
1 changed files with 15 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue