diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2019-08-11 19:29:09 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2019-08-21 23:36:49 +0100 |
commit | 895a15b3218f820af6af714e1dde9f086deba0ca (patch) | |
tree | 7cca552d4e2198a4b24008fa0d1949f5205f46d9 /scene | |
parent | 3bd49dabfa909187d514e018ff7c60339e343c71 (diff) |
Add syntax highlighting cache
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/text_edit.cpp | 21 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
2 files changed, 21 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f137b2618b..f3a4ca9e83 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -573,6 +573,7 @@ void TextEdit::_notification(int p_what) { _update_caches(); _update_wrap_at(); + syntax_highlighting_cache.clear(); } break; case MainLoop::NOTIFICATION_WM_FOCUS_IN: { window_has_focus = true; @@ -3714,6 +3715,15 @@ void TextEdit::_line_edited_from(int p_line) { for (int i = p_line; i < cache_size; i++) { color_region_cache.erase(i); } + + if (syntax_highlighting_cache.size() > 0) { + cache_size = syntax_highlighting_cache.back()->key(); + for (int i = p_line - 1; i < cache_size; i++) { + if (syntax_highlighting_cache.has(i)) { + syntax_highlighting_cache.erase(i); + } + } + } } int TextEdit::get_char_count() { @@ -4569,6 +4579,7 @@ void TextEdit::_set_syntax_highlighting(SyntaxHighlighter *p_syntax_highlighter) syntax_highlighter->set_text_editor(this); syntax_highlighter->_update_cache(); } + syntax_highlighting_cache.clear(); update(); } @@ -4635,6 +4646,7 @@ void TextEdit::clear_colors() { keywords.clear(); color_regions.clear(); color_region_cache.clear(); + syntax_highlighting_cache.clear(); text.clear_width_cache(); } @@ -6707,8 +6719,14 @@ TextEdit::~TextEdit() { /////////////////////////////////////////////////////////////////////////////// Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int p_line) { + if (syntax_highlighting_cache.has(p_line)) { + return syntax_highlighting_cache[p_line]; + } + if (syntax_highlighter != NULL) { - return syntax_highlighter->_get_line_syntax_highlighting(p_line); + Map<int, HighlighterInfo> color_map = syntax_highlighter->_get_line_syntax_highlighting(p_line); + syntax_highlighting_cache[p_line] = color_map; + return color_map; } Map<int, HighlighterInfo> color_map; @@ -6890,6 +6908,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int } } + syntax_highlighting_cache[p_line] = color_map; return color_map; } diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b47dac0902..a52e6a72ba 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -214,6 +214,7 @@ private: } cache; Map<int, int> color_region_cache; + Map<int, Map<int, HighlighterInfo> > syntax_highlighting_cache; struct TextOperation { |