mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
LibWeb: Clean up Selection::move_offset_to_* methods
No functional changes.
This commit is contained in:
parent
2e910dd6e1
commit
09645875ea
Notes:
github-actions[bot]
2025-08-26 08:27:43 +00:00
Author: https://github.com/gmta
Commit: 09645875ea
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5952
1 changed files with 23 additions and 30 deletions
|
@ -567,59 +567,54 @@ GC::Ptr<DOM::Position> Selection::cursor_position() const
|
|||
|
||||
void Selection::move_offset_to_next_character(bool collapse_selection)
|
||||
{
|
||||
auto anchor_node = this->anchor_node();
|
||||
if (!anchor_node || !is<DOM::Text>(*anchor_node))
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
|
||||
auto& text_node = static_cast<DOM::Text&>(*anchor_node);
|
||||
if (auto offset = text_node.grapheme_segmenter().next_boundary(focus_offset()); offset.has_value()) {
|
||||
if (auto offset = text_node->grapheme_segmenter().next_boundary(focus_offset()); offset.has_value()) {
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(*anchor_node, *offset));
|
||||
MUST(collapse(text_node, *offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*anchor_node, anchor_offset(), *anchor_node, *offset));
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Selection::move_offset_to_previous_character(bool collapse_selection)
|
||||
{
|
||||
auto anchor_node = this->anchor_node();
|
||||
if (!anchor_node || !is<DOM::Text>(*anchor_node))
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
|
||||
auto& text_node = static_cast<DOM::Text&>(*anchor_node);
|
||||
if (auto offset = text_node.grapheme_segmenter().previous_boundary(focus_offset()); offset.has_value()) {
|
||||
if (auto offset = text_node->grapheme_segmenter().previous_boundary(focus_offset()); offset.has_value()) {
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(*anchor_node, *offset));
|
||||
MUST(collapse(text_node, *offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*anchor_node, anchor_offset(), *anchor_node, *offset));
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Selection::move_offset_to_next_word(bool collapse_selection)
|
||||
{
|
||||
auto anchor_node = this->anchor_node();
|
||||
if (!anchor_node || !is<DOM::Text>(*anchor_node)) {
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
}
|
||||
|
||||
auto& text_node = static_cast<DOM::Text&>(*anchor_node);
|
||||
while (true) {
|
||||
auto focus_offset = this->focus_offset();
|
||||
if (focus_offset == text_node.data().length_in_code_units()) {
|
||||
if (focus_offset == text_node->data().length_in_code_units())
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto offset = text_node.word_segmenter().next_boundary(focus_offset); offset.has_value()) {
|
||||
auto word = text_node.data().substring_view(focus_offset, *offset - focus_offset);
|
||||
if (auto offset = text_node->word_segmenter().next_boundary(focus_offset); offset.has_value()) {
|
||||
auto word = text_node->data().substring_view(focus_offset, *offset - focus_offset);
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(anchor_node, *offset));
|
||||
MUST(collapse(text_node, *offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*anchor_node, this->anchor_offset(), *anchor_node, *offset));
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *offset));
|
||||
}
|
||||
if (Unicode::Segmenter::should_continue_beyond_word(word))
|
||||
continue;
|
||||
|
@ -630,21 +625,19 @@ void Selection::move_offset_to_next_word(bool collapse_selection)
|
|||
|
||||
void Selection::move_offset_to_previous_word(bool collapse_selection)
|
||||
{
|
||||
auto anchor_node = this->anchor_node();
|
||||
if (!anchor_node || !is<DOM::Text>(*anchor_node)) {
|
||||
auto* text_node = as_if<DOM::Text>(anchor_node().ptr());
|
||||
if (!text_node)
|
||||
return;
|
||||
}
|
||||
|
||||
auto& text_node = static_cast<DOM::Text&>(*anchor_node);
|
||||
while (true) {
|
||||
auto focus_offset = this->focus_offset();
|
||||
if (auto offset = text_node.word_segmenter().previous_boundary(focus_offset); offset.has_value()) {
|
||||
auto word = text_node.data().substring_view(*offset, focus_offset - *offset);
|
||||
if (auto offset = text_node->word_segmenter().previous_boundary(focus_offset); offset.has_value()) {
|
||||
auto word = text_node->data().substring_view(*offset, focus_offset - *offset);
|
||||
if (collapse_selection) {
|
||||
MUST(collapse(anchor_node, *offset));
|
||||
MUST(collapse(text_node, *offset));
|
||||
m_document->reset_cursor_blink_cycle();
|
||||
} else {
|
||||
MUST(set_base_and_extent(*anchor_node, anchor_offset(), *anchor_node, *offset));
|
||||
MUST(set_base_and_extent(*text_node, anchor_offset(), *text_node, *offset));
|
||||
}
|
||||
if (Unicode::Segmenter::should_continue_beyond_word(word))
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue