You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Add comment highlighting to script thumbnails
(cherry picked from commit 46e0161737)
This commit is contained in:
committed by
Rémi Verschelde
parent
71a9932f38
commit
ae99339e9f
@@ -522,6 +522,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
|||||||
Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color");
|
Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color");
|
||||||
Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color");
|
Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color");
|
||||||
Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color");
|
Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color");
|
||||||
|
Color comment_color = EditorSettings::get_singleton()->get("text_editor/highlighting/comment_color");
|
||||||
|
|
||||||
img->lock();
|
img->lock();
|
||||||
|
|
||||||
@@ -542,6 +543,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
|||||||
|
|
||||||
bool prev_is_text = false;
|
bool prev_is_text = false;
|
||||||
bool in_keyword = false;
|
bool in_keyword = false;
|
||||||
|
bool in_comment = false;
|
||||||
for (int i = 0; i < code.length(); i++) {
|
for (int i = 0; i < code.length(); i++) {
|
||||||
|
|
||||||
CharType c = code[i];
|
CharType c = code[i];
|
||||||
@@ -549,6 +551,13 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
|||||||
if (col < thumbnail_size) {
|
if (col < thumbnail_size) {
|
||||||
Color color = text_color;
|
Color color = text_color;
|
||||||
|
|
||||||
|
if (c == '#') {
|
||||||
|
in_comment = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_comment) {
|
||||||
|
color = comment_color;
|
||||||
|
} else {
|
||||||
if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
|
if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
|
||||||
//make symbol a little visible
|
//make symbol a little visible
|
||||||
color = symbol_color;
|
color = symbol_color;
|
||||||
@@ -560,15 +569,18 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
String word = code.substr(i, pos - i);
|
String word = code.substr(i, pos - i);
|
||||||
if (keywords.has(word))
|
if (keywords.has(word)) {
|
||||||
in_keyword = true;
|
in_keyword = true;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (!_is_text_char(c)) {
|
} else if (!_is_text_char(c)) {
|
||||||
in_keyword = false;
|
in_keyword = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_keyword)
|
if (in_keyword) {
|
||||||
color = keyword_color;
|
color = keyword_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Color ul = color;
|
Color ul = color;
|
||||||
ul.a *= 0.5;
|
ul.a *= 0.5;
|
||||||
@@ -577,22 +589,26 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
|||||||
|
|
||||||
prev_is_text = _is_text_char(c);
|
prev_is_text = _is_text_char(c);
|
||||||
}
|
}
|
||||||
|
col++;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
prev_is_text = false;
|
prev_is_text = false;
|
||||||
in_keyword = false;
|
in_keyword = false;
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
in_comment = false;
|
||||||
|
|
||||||
col = x0;
|
col = x0;
|
||||||
line++;
|
line++;
|
||||||
if (line >= available_height / 2)
|
if (line >= available_height / 2)
|
||||||
break;
|
break;
|
||||||
} else if (c == '\t') {
|
} else if (c == '\t') {
|
||||||
col += 3;
|
col += 3;
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
col++;
|
col++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
img->unlock();
|
img->unlock();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user