1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

LibGUI: Update TextEditor to delete emoji based on gbp cluster

Updated TextDocument and TextEditor to use calls to
`find_grapheme_segmentation_boundary` in order to make "correct-feeling"
deletions on backspace and delete keys being pressed
This commit is contained in:
Fausto Tommasi 2023-02-15 07:49:01 -06:00 committed by Tim Flynn
parent 782b1d20f5
commit f7458b3e17
3 changed files with 37 additions and 0 deletions

View file

@ -384,6 +384,34 @@ DeprecatedString TextDocument::text_in_range(TextRange const& a_range) const
return builder.to_deprecated_string();
}
// This function will return the position of the previous grapheme cluster
// break, relative to the cursor, for "correct looking" parsing of unicode based
// on grapheme cluster boundary algorithm.
size_t TextDocument::get_previous_grapheme_cluster_boundary(TextPosition const& cursor) const
{
if (!cursor.is_valid())
return 0;
auto const& line = this->line(cursor.line());
auto index = Unicode::previous_grapheme_segmentation_boundary(line.view(), cursor.column());
return index.value_or(cursor.column() - 1);
}
// This function will return the position of the next grapheme cluster break,
// relative to the cursor, for "correct looking" parsing of unicode based on
// grapheme cluster boundary algorithm.
size_t TextDocument::get_next_grapheme_cluster_boundary(TextPosition const& cursor) const
{
if (!cursor.is_valid())
return 0;
auto const& line = this->line(cursor.line());
auto index = Unicode::next_grapheme_segmentation_boundary(line.view(), cursor.column());
return index.value_or(cursor.column() + 1);
}
u32 TextDocument::code_point_at(TextPosition const& position) const
{
VERIFY(position.line() < line_count());