2020-08-24 13:38:47 -03:00
|
|
|
/*
|
2022-02-10 16:28:48 -03:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2023-04-13 09:44:41 -03:00
|
|
|
* Copyright (c) 2023, Matteo benetti <matteo.benetti@proton.me>
|
2020-08-24 13:38:47 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-24 13:38:47 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CellSyntaxHighlighter.h"
|
|
|
|
|
#include <LibGUI/TextEditor.h>
|
|
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
|
#include <LibJS/Lexer.h>
|
|
|
|
|
|
|
|
|
|
namespace Spreadsheet {
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
void CellSyntaxHighlighter::rehighlight(Palette const& palette)
|
2020-08-24 13:38:47 -03:00
|
|
|
{
|
2023-04-13 09:44:41 -03:00
|
|
|
m_client->clear_spans();
|
|
|
|
|
|
|
|
|
|
if (m_client->get_text().starts_with('=')) {
|
|
|
|
|
|
|
|
|
|
JS::SyntaxHighlighter::rehighlight(palette);
|
|
|
|
|
|
|
|
|
|
auto spans = m_client->spans();
|
2020-08-24 13:38:47 -03:00
|
|
|
|
2023-04-13 09:44:41 -03:00
|
|
|
// Highlight the '='
|
|
|
|
|
spans.empend(
|
|
|
|
|
GUI::TextRange { { 0, 0 }, { 0, 1 } },
|
|
|
|
|
Gfx::TextAttributes {
|
|
|
|
|
palette.syntax_keyword(),
|
|
|
|
|
Optional<Color> {},
|
|
|
|
|
false,
|
|
|
|
|
},
|
|
|
|
|
(u64)-1,
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
if (m_cell && m_cell->thrown_value().has_value()) {
|
|
|
|
|
if (auto value = m_cell->thrown_value().value(); value.is_object() && is<JS::Error>(value.as_object())) {
|
|
|
|
|
auto& error = static_cast<JS::Error const&>(value.as_object());
|
2023-05-28 03:28:43 -03:00
|
|
|
auto& range = error.traceback().first().source_range();
|
2023-04-13 09:44:41 -03:00
|
|
|
|
|
|
|
|
spans.prepend({
|
|
|
|
|
GUI::TextRange { { range.start.line - 1, range.start.column }, { range.end.line - 1, range.end.column } },
|
2022-02-07 11:00:40 -03:00
|
|
|
Gfx::TextAttributes {
|
|
|
|
|
Color::Black,
|
|
|
|
|
Color::Red,
|
|
|
|
|
false,
|
|
|
|
|
},
|
|
|
|
|
(u64)-1,
|
2023-04-13 09:44:41 -03:00
|
|
|
false,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-07 11:00:40 -03:00
|
|
|
}
|
2023-04-13 09:44:41 -03:00
|
|
|
|
|
|
|
|
m_client->do_set_spans(move(spans));
|
2020-12-28 14:16:39 -03:00
|
|
|
}
|
2023-04-13 09:44:41 -03:00
|
|
|
|
2021-02-07 12:56:02 -03:00
|
|
|
m_client->do_update();
|
2020-08-24 13:38:47 -03:00
|
|
|
}
|
|
|
|
|
}
|