LibGUI+LibSyntax: Stringify Highlighter::Language

This patch adds a Highlighter::Language -> string helper and a
callback for Highlighter changes.
This commit is contained in:
thankyouverycool 2022-02-22 15:00:56 -05:00 committed by Andreas Kling
parent 3aa95dd4d5
commit 94b74937d8
Notes: sideshowbarker 2024-07-17 18:19:04 +09:00
4 changed files with 30 additions and 0 deletions

View File

@ -1934,6 +1934,8 @@ void TextEditor::set_syntax_highlighter(OwnPtr<Syntax::Highlighter> highlighter)
m_needs_rehighlight = true;
} else
document().set_spans({});
if (on_highlighter_change)
on_highlighter_change();
}
AutocompleteProvider const* TextEditor::autocomplete_provider() const

View File

@ -107,6 +107,7 @@ public:
Function<void()> on_selection_change;
Function<void()> on_focusin;
Function<void()> on_focusout;
Function<void()> on_highlighter_change;
void set_text(StringView, AllowCallback = AllowCallback::Yes);
void scroll_cursor_into_view();

View File

@ -142,4 +142,30 @@ void Highlighter::register_nested_token_pairs(Vector<MatchingTokenPair> pairs)
m_nested_token_pairs.set(pair);
}
StringView Highlighter::language_string(Language language) const
{
switch (language) {
case Language::Cpp:
return "C++"sv;
case Language::CSS:
return "CSS"sv;
case Language::GitCommit:
return "Git"sv;
case Language::GML:
return "GML"sv;
case Language::HTML:
return "HTML"sv;
case Language::INI:
return "INI"sv;
case Language::JavaScript:
return "JavaScript"sv;
case Language::Shell:
return "Shell"sv;
case Language::SQL:
return "SQL"sv;
default:
VERIFY_NOT_REACHED();
}
}
}

View File

@ -40,6 +40,7 @@ public:
virtual ~Highlighter();
virtual Language language() const = 0;
StringView language_string(Language) const;
virtual void rehighlight(const Palette&) = 0;
virtual void highlight_matching_token_pair();