mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Implement up/down arrow navigation for EditingHostManager
This commit is contained in:
parent
f529a4d98e
commit
2674bd428e
Notes:
github-actions[bot]
2025-09-18 11:40:28 +00:00
Author: https://github.com/trflynn89
Commit: 2674bd428e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5956
Reviewed-by: https://github.com/gmta
5 changed files with 119 additions and 4 deletions
|
|
@ -13,6 +13,7 @@
|
|||
#include <LibWeb/DOM/Position.h>
|
||||
#include <LibWeb/DOM/Range.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/GraphemeEdgeTracker.h>
|
||||
#include <LibWeb/Selection/Selection.h>
|
||||
|
||||
namespace Web::Selection {
|
||||
|
|
@ -650,4 +651,40 @@ void Selection::move_offset_to_previous_word(bool collapse_selection)
|
|||
}
|
||||
}
|
||||
|
||||
void Selection::move_offset_to_next_line(bool collapse_selection)
|
||||
{
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
|
||||
auto new_offset = compute_cursor_position_on_next_line(*text_node, focus_offset());
|
||||
if (!new_offset.has_value())
|
||||
return;
|
||||
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(text_node, *new_offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *new_offset));
|
||||
}
|
||||
}
|
||||
|
||||
void Selection::move_offset_to_previous_line(bool collapse_selection)
|
||||
{
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
|
||||
auto new_offset = compute_cursor_position_on_previous_line(*text_node, focus_offset());
|
||||
if (!new_offset.has_value())
|
||||
return;
|
||||
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(text_node, *new_offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *new_offset));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ public:
|
|||
void move_offset_to_previous_character(bool collapse_selection);
|
||||
void move_offset_to_next_word(bool collapse_selection);
|
||||
void move_offset_to_previous_word(bool collapse_selection);
|
||||
void move_offset_to_next_line(bool collapse_selection);
|
||||
void move_offset_to_previous_line(bool collapse_selection);
|
||||
|
||||
private:
|
||||
Selection(GC::Ref<JS::Realm>, GC::Ref<DOM::Document>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue