summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorMatteo Benetti <matteo.benetti@proton.me>2023-04-13 14:44:41 +0200
committerAndreas Kling <kling@serenityos.org>2023-04-14 10:00:52 +0200
commit3e1626acdcf6088d65610ff8bfed07b92420a0de (patch)
treed8566e899f891bf8a467de56694a8784a1117aab /Userland/Libraries
parentfb47b988ca379433e353a503dbfdddcaa5e3c67f (diff)
downloadserenity-3e1626acdcf6088d65610ff8bfed07b92420a0de.zip
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
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.h1
-rw-r--r--Userland/Libraries/LibSyntax/Highlighter.h1
-rw-r--r--Userland/Libraries/LibSyntax/HighlighterClient.h2
3 files changed, 1 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h
index dfabda73cb..55ddc8946a 100644
--- a/Userland/Libraries/LibGUI/TextEditor.h
+++ b/Userland/Libraries/LibGUI/TextEditor.h
@@ -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(); };
diff --git a/Userland/Libraries/LibSyntax/Highlighter.h b/Userland/Libraries/LibSyntax/Highlighter.h
index c67777c1b8..8ba81ea77b 100644
--- a/Userland/Libraries/LibSyntax/Highlighter.h
+++ b/Userland/Libraries/LibSyntax/Highlighter.h
@@ -125,7 +125,6 @@ public:
}
private:
- virtual Vector<GUI::TextDocumentSpan>& spans() override { return m_spans; }
virtual Vector<GUI::TextDocumentSpan> const& spans() const override { return m_spans; }
virtual void set_span_at_index(size_t index, GUI::TextDocumentSpan span) override { m_spans.at(index) = move(span); }
diff --git a/Userland/Libraries/LibSyntax/HighlighterClient.h b/Userland/Libraries/LibSyntax/HighlighterClient.h
index 3491ca8995..a535a60e85 100644
--- a/Userland/Libraries/LibSyntax/HighlighterClient.h
+++ b/Userland/Libraries/LibSyntax/HighlighterClient.h
@@ -17,9 +17,9 @@ class HighlighterClient {
public:
virtual ~HighlighterClient() = default;
- virtual Vector<GUI::TextDocumentSpan>& spans() = 0;
virtual Vector<GUI::TextDocumentSpan> const& spans() const = 0;
virtual void set_span_at_index(size_t index, GUI::TextDocumentSpan span) = 0;
+ virtual void clear_spans() { do_set_spans({}); };
virtual Vector<GUI::TextDocumentFoldingRegion>& folding_regions() = 0;
virtual Vector<GUI::TextDocumentFoldingRegion> const& folding_regions() const = 0;