mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-12 22:22:55 +00:00
LibWeb: Make DOM::Range more suitable for JS.
This commit is contained in:
parent
4df0eeaa3d
commit
10f9c85090
Notes:
sideshowbarker
2024-07-19 00:56:55 +09:00
Author: https://github.com/asynts
Commit: 10f9c85090
Pull-request: https://github.com/SerenityOS/serenity/pull/4318
Reviewed-by: https://github.com/Lubrsi
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
11 changed files with 186 additions and 69 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <LibGUI/Window.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Range.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
||||
|
@ -346,15 +347,15 @@ 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().normalized();
|
||||
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());
|
||||
m_frame.set_cursor_position({ *range->start_container(), range->start_offset() });
|
||||
|
||||
if (key == KeyCode::Key_Backspace || key == KeyCode::Key_Delete) {
|
||||
if (range.start().node()->is_editable()) {
|
||||
if (range->start_container()->is_editable()) {
|
||||
m_edit_event_handler->handle_delete(range);
|
||||
return true;
|
||||
}
|
||||
|
@ -375,7 +376,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
|
|||
TODO();
|
||||
|
||||
m_frame.cursor_position().set_offset(position.offset() - 1);
|
||||
m_edit_event_handler->handle_delete({ { *position.node(), position.offset() - 1 }, position });
|
||||
m_edit_event_handler->handle_delete(DOM::Range::create(*position.node(), position.offset() - 1, *position.node(), position.offset()));
|
||||
|
||||
return true;
|
||||
} else if (key == KeyCode::Key_Delete) {
|
||||
|
@ -384,7 +385,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
|
|||
if (position.offset() >= downcast<DOM::Text>(position.node())->data().length())
|
||||
TODO();
|
||||
|
||||
m_edit_event_handler->handle_delete({ position, { *position.node(), position.offset() + 1 } });
|
||||
m_edit_event_handler->handle_delete(DOM::Range::create(*position.node(), position.offset(), *position.node(), position.offset() + 1));
|
||||
|
||||
return true;
|
||||
} else if (key == KeyCode::Key_Right) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue