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

LibSyntax+LibGUI+LibJS: Move JS syntax highlighter to LibJS

This is a little bit messy but the basic idea is:

Syntax::Highlighter now has a Syntax::HighlighterClient to talk to the
outside world. It mostly communicates in LibGUI primitives that are
available in headers, so inlineable.

GUI::TextEditor inherits from Syntax::HighlighterClient.

This let us to move GUI::JSSyntaxHighlighter to JS::SyntaxHighlighter
and remove LibGUI's dependency on LibJS.
This commit is contained in:
Andreas Kling 2021-02-07 16:56:02 +01:00
parent 22baa5e64f
commit ddbf20ecf6
23 changed files with 139 additions and 80 deletions

View file

@ -25,7 +25,6 @@
*/
#include "CellSyntaxHighlighter.h"
#include <LibGUI/JSSyntaxHighlighter.h>
#include <LibGUI/TextEditor.h>
#include <LibGfx/Palette.h>
#include <LibJS/Lexer.h>
@ -34,18 +33,17 @@ namespace Spreadsheet {
void CellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
{
ASSERT(m_editor);
auto text = m_editor->text();
m_editor->document().spans().clear();
auto text = m_client->get_text();
m_client->spans().clear();
if (!text.starts_with('=')) {
m_editor->update();
m_client->do_update();
return;
}
JSSyntaxHighlighter::rehighlight(palette);
JS::SyntaxHighlighter::rehighlight(palette);
// Highlight the '='
m_editor->document().spans().empend(
m_client->spans().empend(
GUI::TextRange { { 0, 0 }, { 0, 1 } },
Gfx::TextAttributes {
palette.syntax_keyword(),
@ -59,7 +57,7 @@ void CellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
if (m_cell && m_cell->exception()) {
auto range = m_cell->exception()->source_ranges().first();
GUI::TextRange text_range { { range.start.line - 1, range.start.column }, { range.end.line - 1, range.end.column - 1 } };
m_editor->document().spans().prepend(
m_client->spans().prepend(
GUI::TextDocumentSpan {
text_range,
Gfx::TextAttributes {
@ -71,7 +69,7 @@ void CellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
nullptr,
false });
}
m_editor->update();
m_client->do_update();
}
CellSyntaxHighlighter::~CellSyntaxHighlighter()