mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13: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:
parent
22baa5e64f
commit
ddbf20ecf6
23 changed files with 139 additions and 80 deletions
|
@ -28,13 +28,10 @@
|
|||
#include "ConsoleWidget.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/DOMTreeModel.h>
|
||||
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||
|
||||
namespace Browser {
|
||||
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/MarkupGenerator.h>
|
||||
#include <LibJS/Parser.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/SyntaxHighlighter.h>
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
|
@ -66,7 +66,7 @@ ConsoleWidget::ConsoleWidget()
|
|||
bottom_container.set_fixed_height(22);
|
||||
|
||||
m_input = bottom_container.add<GUI::TextBox>();
|
||||
m_input->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
|
||||
m_input->set_syntax_highlighter(make<JS::SyntaxHighlighter>());
|
||||
// FIXME: Syntax Highlighting breaks the cursor's position on non fixed-width fonts.
|
||||
m_input->set_font(Gfx::FontDatabase::default_fixed_width_font());
|
||||
m_input->set_history_enabled(true);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "Cell.h"
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
#include <LibJS/SyntaxHighlighter.h>
|
||||
|
||||
namespace Spreadsheet {
|
||||
|
||||
class CellSyntaxHighlighter final : public GUI::JSSyntaxHighlighter {
|
||||
class CellSyntaxHighlighter final : public JS::SyntaxHighlighter {
|
||||
public:
|
||||
CellSyntaxHighlighter() { }
|
||||
virtual ~CellSyntaxHighlighter() override;
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include <LibGUI/ColorInput.h>
|
||||
#include <LibGUI/ComboBox.h>
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/ListView.h>
|
||||
#include <LibGUI/SpinBox.h>
|
||||
|
@ -44,6 +43,7 @@
|
|||
#include <LibGUI/TextEditor.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibJS/SyntaxHighlighter.h>
|
||||
|
||||
REGISTER_WIDGET(Spreadsheet, ConditionsView);
|
||||
|
||||
|
@ -425,7 +425,7 @@ ConditionView::ConditionView(ConditionalFormat& fmt)
|
|||
m_format.background_color = bg_input.color();
|
||||
};
|
||||
|
||||
formula_editor.set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
|
||||
formula_editor.set_syntax_highlighter(make<JS::SyntaxHighlighter>());
|
||||
formula_editor.set_should_hide_unnecessary_scrollbars(true);
|
||||
formula_editor.set_font(&Gfx::FontDatabase::default_fixed_width_font());
|
||||
formula_editor.on_change = [&] {
|
||||
|
|
|
@ -7,4 +7,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_app(TextEditor ICON app-text-editor)
|
||||
target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp)
|
||||
target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp LibJS)
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#include <LibGUI/FontPicker.h>
|
||||
#include <LibGUI/GMLSyntaxHighlighter.h>
|
||||
#include <LibGUI/INISyntaxHighlighter.h>
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/MenuBar.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
|
@ -57,6 +56,7 @@
|
|||
#include <LibGUI/ToolBarContainer.h>
|
||||
#include <LibGUI/VimEditingEngine.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibJS/SyntaxHighlighter.h>
|
||||
#include <LibMarkdown/Document.h>
|
||||
#include <LibWeb/OutOfProcessWebView.h>
|
||||
#include <string.h>
|
||||
|
@ -476,7 +476,7 @@ TextEditorWidget::TextEditorWidget()
|
|||
syntax_menu.add_action(*m_cpp_highlight);
|
||||
|
||||
m_js_highlight = GUI::Action::create_checkable("JavaScript", [&](auto&) {
|
||||
m_editor->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
|
||||
m_editor->set_syntax_highlighter(make<JS::SyntaxHighlighter>());
|
||||
m_editor->update();
|
||||
});
|
||||
syntax_actions.add_action(*m_js_highlight);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue