diff options
author | Oriko <oriko1010@protonmail.com> | 2020-03-12 17:23:54 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-12 19:04:59 +0100 |
commit | 137d68a2aee129cdbf856dccd0a33b7591ee444a (patch) | |
tree | 603681b4957cf32148fb092b841952f8a23c7dc3 /Libraries | |
parent | bacd3dd57ac54759b50b61ce80c727e86be9c054 (diff) | |
download | serenity-137d68a2aee129cdbf856dccd0a33b7591ee444a.zip |
HackStudio: Abstract over syntax highlighter
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/CppSyntaxHighlighter.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibGUI/CppSyntaxHighlighter.h | 3 | ||||
-rw-r--r-- | Libraries/LibGUI/SyntaxHighlighter.h | 3 | ||||
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 5 |
4 files changed, 19 insertions, 4 deletions
diff --git a/Libraries/LibGUI/CppSyntaxHighlighter.cpp b/Libraries/LibGUI/CppSyntaxHighlighter.cpp index 76561339e0..aa68539ede 100644 --- a/Libraries/LibGUI/CppSyntaxHighlighter.cpp +++ b/Libraries/LibGUI/CppSyntaxHighlighter.cpp @@ -37,6 +37,18 @@ static TextStyle style_for_token_type(CppToken::Type type) } } +bool CppSyntaxHighlighter::is_identifier(void* token) const +{ + auto cpp_token = static_cast<GUI::CppToken::Type>(reinterpret_cast<size_t>(token)); + return cpp_token == GUI::CppToken::Type::Identifier; +} + +bool CppSyntaxHighlighter::is_navigatable(void* token) const +{ + auto cpp_token = static_cast<GUI::CppToken::Type>(reinterpret_cast<size_t>(token)); + return cpp_token == GUI::CppToken::Type::IncludePath; +} + void CppSyntaxHighlighter::rehighlight() { ASSERT(m_editor); diff --git a/Libraries/LibGUI/CppSyntaxHighlighter.h b/Libraries/LibGUI/CppSyntaxHighlighter.h index 0f77c88cd7..a3f50deb0a 100644 --- a/Libraries/LibGUI/CppSyntaxHighlighter.h +++ b/Libraries/LibGUI/CppSyntaxHighlighter.h @@ -9,6 +9,9 @@ public: CppSyntaxHighlighter() {} virtual ~CppSyntaxHighlighter() override; + virtual bool is_identifier(void*) const override; + virtual bool is_navigatable(void*) const override; + virtual SyntaxLanguage language() const override { return SyntaxLanguage::Cpp; } virtual void rehighlight() override; virtual void highlight_matching_token_pair() override; diff --git a/Libraries/LibGUI/SyntaxHighlighter.h b/Libraries/LibGUI/SyntaxHighlighter.h index 568dd403d4..8a15114381 100644 --- a/Libraries/LibGUI/SyntaxHighlighter.h +++ b/Libraries/LibGUI/SyntaxHighlighter.h @@ -22,6 +22,9 @@ public: virtual void rehighlight() = 0; virtual void highlight_matching_token_pair() = 0; + virtual bool is_identifier(void*) const { return false; }; + virtual bool is_navigatable(void*) const { return false; }; + void attach(TextEditor& editor); void detach(); void cursor_did_change(); diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 78bb871bce..babc705810 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -1497,10 +1497,7 @@ void TextEditor::flush_pending_change_notification_if_needed() const SyntaxHighlighter* TextEditor::syntax_highlighter() const { - if (m_highlighter) - return m_highlighter.ptr(); - else - return nullptr; + return m_highlighter.ptr(); } void TextEditor::set_syntax_highlighter(OwnPtr<SyntaxHighlighter> highlighter) |