From 46db0febf732d8c502765d29b9f689571fa45722 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 31 Oct 2024 17:56:42 +0100 Subject: [PATCH] LibUnicode+LibWeb: Move should_continue_beyond_word helper in Segmenter --- Userland/Libraries/LibUnicode/Segmenter.cpp | 10 ++++++++++ Userland/Libraries/LibUnicode/Segmenter.h | 2 ++ .../Libraries/LibWeb/DOM/EditingHostManager.cpp | 14 ++------------ .../LibWeb/HTML/FormAssociatedElement.cpp | 14 ++------------ 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Userland/Libraries/LibUnicode/Segmenter.cpp b/Userland/Libraries/LibUnicode/Segmenter.cpp index 953f36a73d3..ec73eb1e7b8 100644 --- a/Userland/Libraries/LibUnicode/Segmenter.cpp +++ b/Userland/Libraries/LibUnicode/Segmenter.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -235,4 +236,13 @@ NonnullOwnPtr Segmenter::create(StringView locale, SegmenterGranulari return make(segmenter.release_nonnull(), segmenter_granularity); } +bool Segmenter::should_continue_beyond_word(Utf8View const& word) +{ + for (auto code_point : word) { + if (!code_point_has_punctuation_general_category(code_point) && !code_point_has_separator_general_category(code_point)) + return false; + } + return true; +} + } diff --git a/Userland/Libraries/LibUnicode/Segmenter.h b/Userland/Libraries/LibUnicode/Segmenter.h index 7b5862479c9..d4cb462ca55 100644 --- a/Userland/Libraries/LibUnicode/Segmenter.h +++ b/Userland/Libraries/LibUnicode/Segmenter.h @@ -27,6 +27,8 @@ public: static NonnullOwnPtr create(StringView locale, SegmenterGranularity segmenter_granularity); virtual ~Segmenter() = default; + static bool should_continue_beyond_word(Utf8View const&); + SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; } virtual NonnullOwnPtr clone() const = 0; diff --git a/Userland/Libraries/LibWeb/DOM/EditingHostManager.cpp b/Userland/Libraries/LibWeb/DOM/EditingHostManager.cpp index 47e23408e1e..e3fe6fc26a9 100644 --- a/Userland/Libraries/LibWeb/DOM/EditingHostManager.cpp +++ b/Userland/Libraries/LibWeb/DOM/EditingHostManager.cpp @@ -166,16 +166,6 @@ void EditingHostManager::decrement_cursor_position_offset(CollapseSelection coll } } -static bool should_continue_beyond_word(Utf8View const& word) -{ - for (auto code_point : word) { - if (!Unicode::code_point_has_punctuation_general_category(code_point) && !Unicode::code_point_has_separator_general_category(code_point)) - return false; - } - - return true; -} - void EditingHostManager::increment_cursor_position_to_next_word(CollapseSelection collapse) { auto selection = m_document->get_selection(); @@ -200,7 +190,7 @@ void EditingHostManager::increment_cursor_position_to_next_word(CollapseSelectio } else { MUST(selection->set_base_and_extent(*node, selection->anchor_offset(), *node, *offset)); } - if (should_continue_beyond_word(word)) + if (Unicode::Segmenter::should_continue_beyond_word(word)) continue; } break; @@ -227,7 +217,7 @@ void EditingHostManager::decrement_cursor_position_to_previous_word(CollapseSele } else { MUST(selection->set_base_and_extent(*node, selection->anchor_offset(), *node, *offset)); } - if (should_continue_beyond_word(word)) + if (Unicode::Segmenter::should_continue_beyond_word(word)) continue; } break; diff --git a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp index f726c920f52..cf15586fcd1 100644 --- a/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp @@ -757,16 +757,6 @@ void FormAssociatedTextControlElement::decrement_cursor_position_offset(Collapse selection_was_changed(); } -static bool should_continue_beyond_word(Utf8View const& word) -{ - for (auto code_point : word) { - if (!Unicode::code_point_has_punctuation_general_category(code_point) && !Unicode::code_point_has_separator_general_category(code_point)) - return false; - } - - return true; -} - void FormAssociatedTextControlElement::increment_cursor_position_to_next_word(CollapseSelection collapse) { auto const text_node = form_associated_element_to_text_node(); @@ -781,7 +771,7 @@ void FormAssociatedTextControlElement::increment_cursor_position_to_next_word(Co } else { m_selection_end = *offset; } - if (should_continue_beyond_word(word)) + if (Unicode::Segmenter::should_continue_beyond_word(word)) continue; } break; @@ -804,7 +794,7 @@ void FormAssociatedTextControlElement::decrement_cursor_position_to_previous_wor } else { m_selection_end = *offset; } - if (should_continue_beyond_word(word)) + if (Unicode::Segmenter::should_continue_beyond_word(word)) continue; } break;