From c2884d29d668538382a02bacaa6d05a9acebf6cf Mon Sep 17 00:00:00 2001 From: Oriko Date: Fri, 13 Mar 2020 00:53:22 +0200 Subject: [PATCH] TextEditor: Use Javascript syntax highlighter --- Applications/TextEditor/Makefile | 2 +- Applications/TextEditor/TextEditorWidget.cpp | 12 ++++++++++++ Applications/TextEditor/TextEditorWidget.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Applications/TextEditor/Makefile b/Applications/TextEditor/Makefile index 10d87dff0a..051788ffa6 100755 --- a/Applications/TextEditor/Makefile +++ b/Applications/TextEditor/Makefile @@ -4,6 +4,6 @@ OBJS = \ PROGRAM = TextEditor -LIB_DEPS = GUI Gfx VT IPC Thread Pthread Core +LIB_DEPS = GUI Gfx VT IPC Thread Pthread Core JS include ../../Makefile.common diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 663a484dfb..8fac10bf2f 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -402,6 +403,15 @@ TextEditorWidget::TextEditorWidget() syntax_actions.add_action(*m_cpp_highlight); syntax_menu->add_action(*m_cpp_highlight); + m_js_highlight = GUI::Action::create("Javascript", [&](GUI::Action& action) { + action.set_checked(true); + m_editor->set_syntax_highlighter(make()); + m_editor->update(); + }); + m_js_highlight->set_checkable(true); + syntax_actions.add_action(*m_js_highlight); + syntax_menu->add_action(*m_js_highlight); + auto view_menu = GUI::Menu::construct("View"); view_menu->add_action(*m_line_wrapping_setting_action); view_menu->add_separator(); @@ -446,6 +456,8 @@ void TextEditorWidget::set_path(const FileSystemPath& file) if (m_extension == "cpp" || m_extension == "h") m_cpp_highlight->activate(); + else if (m_extension == "js") + m_js_highlight->activate(); else m_plain_text_highlight->activate(); diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index 66a4d4edc0..89e22f48bd 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -82,6 +82,7 @@ private: GUI::ActionGroup syntax_actions; RefPtr m_plain_text_highlight; RefPtr m_cpp_highlight; + RefPtr m_js_highlight; bool m_document_dirty { false }; bool m_document_opening { false };