mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
HackStudio: Abstract over syntax highlighter
This commit is contained in:
parent
bacd3dd57a
commit
137d68a2ae
5 changed files with 32 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue