From dc388297ebe661908f4da549dab2c57697a7414b Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 20 May 2021 23:17:30 +0430 Subject: [PATCH] TextEditor+Browser: Enable HTML syntax highlighting on HTML documents --- Userland/Applications/Browser/Tab.cpp | 2 ++ Userland/Applications/TextEditor/MainWidget.cpp | 10 ++++++++++ Userland/Applications/TextEditor/MainWidget.h | 1 + 3 files changed, 13 insertions(+) diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 2af6c42ed6..e7e05682e5 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ void Tab::view_source(const URL& url, const String& source) auto& editor = window->set_main_widget(); editor.set_text(source); editor.set_mode(GUI::TextEditor::ReadOnly); + editor.set_syntax_highlighter(make()); editor.set_ruler_visible(true); window->resize(640, 480); window->set_title(url.to_string()); diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 44949060ce..a893d511eb 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -547,6 +548,13 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar) syntax_actions.add_action(*m_js_highlight); syntax_menu.add_action(*m_js_highlight); + m_html_highlight = GUI::Action::create_checkable("&HTML File", [&](auto&) { + m_editor->set_syntax_highlighter(make()); + m_editor->update(); + }); + syntax_actions.add_action(*m_html_highlight); + syntax_menu.add_action(*m_html_highlight); + m_gml_highlight = GUI::Action::create_checkable("&GML", [&](auto&) { m_editor->set_syntax_highlighter(make()); m_editor->update(); @@ -598,6 +606,8 @@ void MainWidget::set_path(const LexicalPath& lexical_path) m_ini_highlight->activate(); } else if (m_extension == "sql") { m_sql_highlight->activate(); + } else if (m_extension == "html") { + m_html_highlight->activate(); } else { m_plain_text_highlight->activate(); } diff --git a/Userland/Applications/TextEditor/MainWidget.h b/Userland/Applications/TextEditor/MainWidget.h index dc19f487b9..301cb84f80 100644 --- a/Userland/Applications/TextEditor/MainWidget.h +++ b/Userland/Applications/TextEditor/MainWidget.h @@ -111,6 +111,7 @@ private: RefPtr m_plain_text_highlight; RefPtr m_cpp_highlight; RefPtr m_js_highlight; + RefPtr m_html_highlight; RefPtr m_gml_highlight; RefPtr m_ini_highlight; RefPtr m_shell_highlight;