LibWeb: Rename CharacterData's segmenter indicate it is for graphemes

We will be adding a word segmenter as well, so this is to disambiguate
the two.
This commit is contained in:
Timothy Flynn 2024-09-05 09:59:59 -04:00 committed by Andreas Kling
commit eece7697fd
Notes: github-actions[bot] 2024-09-06 05:44:12 +00:00
4 changed files with 12 additions and 12 deletions

View file

@ -128,8 +128,8 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
document().set_needs_layout(); document().set_needs_layout();
if (m_segmenter) if (m_grapheme_segmenter)
m_segmenter->set_segmented_text(m_data); m_grapheme_segmenter->set_segmented_text(m_data);
return {}; return {};
} }
@ -155,14 +155,14 @@ WebIDL::ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count
return replace_data(offset, count, String {}); return replace_data(offset, count, String {});
} }
Unicode::Segmenter& CharacterData::segmenter() Unicode::Segmenter& CharacterData::grapheme_segmenter()
{ {
if (!m_segmenter) { if (!m_grapheme_segmenter) {
m_segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme); m_grapheme_segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
m_segmenter->set_segmented_text(m_data); m_grapheme_segmenter->set_segmented_text(m_data);
} }
return *m_segmenter; return *m_grapheme_segmenter;
} }
} }

View file

@ -40,7 +40,7 @@ public:
WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units); WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units);
WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&); WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&);
Unicode::Segmenter& segmenter(); Unicode::Segmenter& grapheme_segmenter();
protected: protected:
CharacterData(Document&, NodeType, String const&); CharacterData(Document&, NodeType, String const&);
@ -50,7 +50,7 @@ protected:
private: private:
String m_data; String m_data;
OwnPtr<Unicode::Segmenter> m_segmenter; OwnPtr<Unicode::Segmenter> m_grapheme_segmenter;
}; };
} }

View file

@ -41,7 +41,7 @@ bool Position::increment_offset()
auto& node = verify_cast<DOM::Text>(*m_node); auto& node = verify_cast<DOM::Text>(*m_node);
if (auto offset = node.segmenter().next_boundary(m_offset); offset.has_value()) { if (auto offset = node.grapheme_segmenter().next_boundary(m_offset); offset.has_value()) {
m_offset = *offset; m_offset = *offset;
return true; return true;
} }
@ -57,7 +57,7 @@ bool Position::decrement_offset()
auto& node = verify_cast<DOM::Text>(*m_node); auto& node = verify_cast<DOM::Text>(*m_node);
if (auto offset = node.segmenter().previous_boundary(m_offset); offset.has_value()) { if (auto offset = node.grapheme_segmenter().previous_boundary(m_offset); offset.has_value()) {
m_offset = *offset; m_offset = *offset;
return true; return true;
} }

View file

@ -22,7 +22,7 @@ void EditEventHandler::handle_delete_character_after(JS::NonnullGCPtr<DOM::Docum
auto& node = verify_cast<DOM::Text>(*cursor_position->node()); auto& node = verify_cast<DOM::Text>(*cursor_position->node());
auto& text = node.data(); auto& text = node.data();
auto next_offset = node.segmenter().next_boundary(cursor_position->offset()); auto next_offset = node.grapheme_segmenter().next_boundary(cursor_position->offset());
if (!next_offset.has_value()) { if (!next_offset.has_value()) {
// FIXME: Move to the next node and delete the first character there. // FIXME: Move to the next node and delete the first character there.
return; return;