mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
LibWeb: Port text segmentation to the ICU text segmenter
This commit is contained in:
parent
14071c52f9
commit
12f177e9e9
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/trflynn89
Commit: 12f177e9e9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/218
5 changed files with 40 additions and 20 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibUnicode/Segmentation.h>
|
||||
#include <LibLocale/Segmenter.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Position.h>
|
||||
#include <LibWeb/DOM/Range.h>
|
||||
|
@ -22,15 +22,15 @@ void EditEventHandler::handle_delete_character_after(JS::NonnullGCPtr<DOM::Posit
|
|||
auto& node = verify_cast<DOM::Text>(*cursor_position->node());
|
||||
auto& text = node.data();
|
||||
|
||||
auto next_grapheme_offset = Unicode::next_grapheme_segmentation_boundary(Utf8View { text }, cursor_position->offset());
|
||||
if (!next_grapheme_offset.has_value()) {
|
||||
auto next_offset = node.segmenter().next_boundary(cursor_position->offset());
|
||||
if (!next_offset.has_value()) {
|
||||
// FIXME: Move to the next node and delete the first character there.
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(text.bytes_as_string_view().substring_view(0, cursor_position->offset()));
|
||||
builder.append(text.bytes_as_string_view().substring_view(*next_grapheme_offset));
|
||||
builder.append(text.bytes_as_string_view().substring_view(*next_offset));
|
||||
node.set_data(MUST(builder.to_string()));
|
||||
|
||||
m_navigable->did_edit({});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue