Skip to content

Commit c2884d2

Browse files
oriko1010awesomekling
authored andcommitted
TextEditor: Use Javascript syntax highlighter
1 parent 196352e commit c2884d2

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Applications/TextEditor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ OBJS = \
44

55
PROGRAM = TextEditor
66

7-
LIB_DEPS = GUI Gfx VT IPC Thread Pthread Core
7+
LIB_DEPS = GUI Gfx VT IPC Thread Pthread Core JS
88

99
include ../../Makefile.common

Applications/TextEditor/TextEditorWidget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <LibGUI/CppSyntaxHighlighter.h>
3939
#include <LibGUI/FilePicker.h>
4040
#include <LibGUI/FontDatabase.h>
41+
#include <LibGUI/JSSyntaxHighlighter.h>
4142
#include <LibGUI/Menu.h>
4243
#include <LibGUI/MenuBar.h>
4344
#include <LibGUI/MessageBox.h>
@@ -402,6 +403,15 @@ TextEditorWidget::TextEditorWidget()
402403
syntax_actions.add_action(*m_cpp_highlight);
403404
syntax_menu->add_action(*m_cpp_highlight);
404405

406+
m_js_highlight = GUI::Action::create("Javascript", [&](GUI::Action& action) {
407+
action.set_checked(true);
408+
m_editor->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
409+
m_editor->update();
410+
});
411+
m_js_highlight->set_checkable(true);
412+
syntax_actions.add_action(*m_js_highlight);
413+
syntax_menu->add_action(*m_js_highlight);
414+
405415
auto view_menu = GUI::Menu::construct("View");
406416
view_menu->add_action(*m_line_wrapping_setting_action);
407417
view_menu->add_separator();
@@ -446,6 +456,8 @@ void TextEditorWidget::set_path(const FileSystemPath& file)
446456

447457
if (m_extension == "cpp" || m_extension == "h")
448458
m_cpp_highlight->activate();
459+
else if (m_extension == "js")
460+
m_js_highlight->activate();
449461
else
450462
m_plain_text_highlight->activate();
451463

Applications/TextEditor/TextEditorWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class TextEditorWidget final : public GUI::Widget {
8282
GUI::ActionGroup syntax_actions;
8383
RefPtr<GUI::Action> m_plain_text_highlight;
8484
RefPtr<GUI::Action> m_cpp_highlight;
85+
RefPtr<GUI::Action> m_js_highlight;
8586

8687
bool m_document_dirty { false };
8788
bool m_document_opening { false };

0 commit comments

Comments
 (0)