1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibLine: Don't compare byte and code point counts of the input text

This commit fixes the odd state after pasting some text containing
multibyte code points.
This also increases the input buffer size, as reading 16 bytes at a time
felt slightly laggy when pasting a large number of emojis :^)
This commit is contained in:
Ali Mohammad Pur 2023-12-15 14:59:16 +03:30 committed by Andreas Kling
parent e28ac74e0b
commit 99cc0514a7

View file

@ -384,7 +384,7 @@ void Editor::insert(StringView string_view)
insert(ch);
}
void Editor::insert(const u32 cp)
void Editor::insert(u32 const cp)
{
StringBuilder builder;
builder.append(Utf32View(&cp, 1));
@ -842,7 +842,7 @@ ErrorOr<void> Editor::handle_read_event()
auto prohibit_scope = prohibit_input();
char keybuf[16];
char keybuf[1024];
ssize_t nread = 0;
if (!m_incomplete_data.size())
@ -1235,10 +1235,11 @@ ErrorOr<void> Editor::handle_read_event()
insert(code_point);
}
if (consumed_code_points == m_incomplete_data.size()) {
if (consumed_code_points == valid_bytes) {
m_incomplete_data.clear();
} else {
for (size_t i = 0; i < consumed_code_points; ++i)
auto bytes_to_drop = input_view.byte_offset_of(consumed_code_points + 1);
for (size_t i = 0; i < bytes_to_drop; ++i)
m_incomplete_data.take_first();
}