summaryrefslogtreecommitdiff
path: root/scene/resources/syntax_highlighter.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/syntax_highlighter.h')
-rw-r--r--scene/resources/syntax_highlighter.h87
1 files changed, 81 insertions, 6 deletions
diff --git a/scene/resources/syntax_highlighter.h b/scene/resources/syntax_highlighter.h
index 7059ef4ce1..40a8870b45 100644
--- a/scene/resources/syntax_highlighter.h
+++ b/scene/resources/syntax_highlighter.h
@@ -38,8 +38,13 @@ class TextEdit;
class SyntaxHighlighter : public Resource {
GDCLASS(SyntaxHighlighter, Resource)
+private:
+ Map<int, Dictionary> highlighting_cache;
+ void _line_edited_from(int p_line);
+
protected:
- TextEdit *text_edit;
+ ObjectID text_edit_instance_id; // For validity check
+ TextEdit *text_edit = nullptr;
static void _bind_methods();
@@ -47,19 +52,89 @@ public:
Dictionary get_line_syntax_highlighting(int p_line);
virtual Dictionary _get_line_syntax_highlighting(int p_line) { return Dictionary(); }
+ void clear_highlighting_cache();
+ virtual void _clear_highlighting_cache() {}
+
void update_cache();
virtual void _update_cache() {}
- virtual String _get_name() const;
- virtual Array _get_supported_languages() const;
-
void set_text_edit(TextEdit *p_text_edit);
TextEdit *get_text_edit();
- virtual Ref<SyntaxHighlighter> _create() const;
-
SyntaxHighlighter() {}
virtual ~SyntaxHighlighter() {}
};
+///////////////////////////////////////////////////////////////////////////////
+
+class CodeHighlighter : public SyntaxHighlighter {
+ GDCLASS(CodeHighlighter, SyntaxHighlighter)
+
+private:
+ struct ColorRegion {
+ Color color;
+ String start_key;
+ String end_key;
+ bool line_only;
+ };
+ Vector<ColorRegion> color_regions;
+ Map<int, int> color_region_cache;
+
+ Dictionary keywords;
+ Dictionary member_keywords;
+
+ Color font_color;
+ Color member_color;
+ Color function_color;
+ Color symbol_color;
+ Color number_color;
+
+protected:
+ static void _bind_methods();
+
+public:
+ virtual Dictionary _get_line_syntax_highlighting(int p_line) override;
+
+ virtual void _clear_highlighting_cache() override;
+ virtual void _update_cache() override;
+
+ void add_keyword_color(const String &p_keyword, const Color &p_color);
+ void remove_keyword_color(const String &p_keyword);
+ bool has_keyword_color(const String &p_keyword) const;
+ Color get_keyword_color(const String &p_keyword) const;
+
+ void set_keyword_colors(const Dictionary p_keywords);
+ void clear_keyword_colors();
+ Dictionary get_keyword_colors() const;
+
+ void add_member_keyword_color(const String &p_member_keyword, const Color &p_color);
+ void remove_member_keyword_color(const String &p_member_keyword);
+ bool has_member_keyword_color(const String &p_member_keyword) const;
+ Color get_member_keyword_color(const String &p_member_keyword) const;
+
+ void set_member_keyword_colors(const Dictionary &p_color_regions);
+ void clear_member_keyword_colors();
+ Dictionary get_member_keyword_colors() const;
+
+ void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
+ void remove_color_region(const String &p_start_key);
+ bool has_color_region(const String &p_start_key) const;
+
+ void set_color_regions(const Dictionary &p_member_keyword);
+ void clear_color_regions();
+ Dictionary get_color_regions() const;
+
+ void set_number_color(Color p_color);
+ Color get_number_color() const;
+
+ void set_symbol_color(Color p_color);
+ Color get_symbol_color() const;
+
+ void set_function_color(Color p_color);
+ Color get_function_color() const;
+
+ void set_member_variable_color(Color p_color);
+ Color get_member_variable_color() const;
+};
+
#endif