1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

Spreadsheet+LibSyntax: Never insert spans directly

Function `CellSyntaxHighlighter::rehighlight()` direct inserted spans
to TextDocument `m_span` vector missing out important reordering and
merging operation carried out by `TextDocument::set_spans()`.

This caused overlapping spans for a cell with only a `=` symbol
(one for the actual token and one for the highlighting) to
miscalculate `start` and `end` value and a `length` value (of
`size_t` type) with a `0-1` substraction (result: 18446744073709551615)
causing `Utf32View::substring_view()` to fail the
`!Checked<size_t>::addition_would_overflow(offset, length)` assertion

This remove the possibility to directly alter `TextDocument`'s spans
thus forcing the utilization of `HighlighterClient::do_set_spans()`
interface function.

Proper refactor have been applied to
`CellSyntaxHighlighter::rehighlight()` function
This commit is contained in:
Matteo Benetti 2023-04-13 14:44:41 +02:00 committed by Andreas Kling
parent fb47b988ca
commit 3e1626acdc
4 changed files with 31 additions and 30 deletions

View file

@ -306,7 +306,6 @@ private:
virtual void document_did_update_undo_stack() override;
// ^Syntax::HighlighterClient
virtual Vector<TextDocumentSpan>& spans() final { return document().spans(); }
virtual Vector<TextDocumentSpan> const& spans() const final { return document().spans(); }
virtual void set_span_at_index(size_t index, TextDocumentSpan span) final { document().set_span_at_index(index, move(span)); }
virtual Vector<GUI::TextDocumentFoldingRegion>& folding_regions() final { return document().folding_regions(); };