From e42c604bc3446cb57cca3dca8e2c4872dc458f06 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 21 Feb 2023 13:11:37 +0100 Subject: [PATCH] Ported: Switch from recursion to iterative for backfilling colour regions. - Paulb23 https://github.com/godotengine/godot/commit/ee4a1c99a78a4fc2d39e953b358a764ef8eae0e4 --- modules/gdscript/editor/gdscript_highlighter.cpp | 10 ++++++++++ scene/resources/syntax_highlighter.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index d0caec635..3bbab1145 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -74,9 +74,19 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) color_region_cache[p_line] = -1; int in_region = -1; if (p_line != 0) { + int prev_region_line = p_line - 1; + while (prev_region_line > 0 && !color_region_cache.has(prev_region_line)) { + prev_region_line--; + } + + for (int i = prev_region_line; i < p_line - 1; i++) { + get_line_syntax_highlighting(i); + } + if (!color_region_cache.has(p_line - 1)) { get_line_syntax_highlighting(p_line - 1); } + in_region = color_region_cache[p_line - 1]; } diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index 0fac59038..34ba30fc4 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -160,9 +160,19 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) { color_region_cache[p_line] = -1; int in_region = -1; if (p_line != 0) { + int prev_region_line = p_line - 1; + while (prev_region_line > 0 && !color_region_cache.has(prev_region_line)) { + prev_region_line--; + } + + for (int i = prev_region_line; i < p_line - 1; i++) { + get_line_syntax_highlighting(i); + } + if (!color_region_cache.has(p_line - 1)) { get_line_syntax_highlighting(p_line - 1); } + in_region = color_region_cache[p_line - 1]; }