mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 00:42:54 +00:00
LibGUI: Fix crash in TextDocument::remove(TextRange)
Oops, we can't be appending substrings of a string we just deleted! Fix this by building up the new line instead of trying to clear and append in place. This works out nicely as we now do fewer document view updates when removing a range. :^)
This commit is contained in:
parent
30a3b8333a
commit
6060c7444b
Notes:
sideshowbarker
2024-07-19 06:32:57 +09:00
Author: https://github.com/awesomekling
Commit: 6060c7444b
2 changed files with 13 additions and 3 deletions
|
@ -117,6 +117,12 @@ void TextDocumentLine::clear(TextDocument& document)
|
|||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::set_text(TextDocument& document, const Vector<u32> text)
|
||||
{
|
||||
m_text = move(text);
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void TextDocumentLine::set_text(TextDocument& document, const StringView& text)
|
||||
{
|
||||
if (text.is_empty()) {
|
||||
|
@ -132,6 +138,8 @@ void TextDocumentLine::set_text(TextDocument& document, const StringView& text)
|
|||
|
||||
void TextDocumentLine::append(TextDocument& document, const u32* codepoints, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
m_text.append(codepoints, length);
|
||||
document.update_views({});
|
||||
}
|
||||
|
@ -588,9 +596,10 @@ void TextDocument::remove(const TextRange& unnormalized_range)
|
|||
ASSERT(range.start().line() == range.end().line() - 1);
|
||||
auto& first_line = line(range.start().line());
|
||||
auto& second_line = line(range.end().line());
|
||||
first_line.clear(*this);
|
||||
first_line.append(*this, first_line.codepoints(), range.start().column());
|
||||
first_line.append(*this, second_line.codepoints() + range.end().column(), second_line.length() - range.end().column());
|
||||
Vector<u32> codepoints;
|
||||
codepoints.append(first_line.codepoints(), range.start().column());
|
||||
codepoints.append(second_line.codepoints() + range.end().column(), second_line.length() - range.end().column());
|
||||
first_line.set_text(*this, move(codepoints));
|
||||
remove_line(range.end().line());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue