You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Highlight control flow keywords with a different color
This makes them easier to distinguish from other keywords.
This commit is contained in:
@@ -491,10 +491,15 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
List<String> kwors;
|
||||
scr->get_language()->get_reserved_words(&kwors);
|
||||
|
||||
Set<String> control_flow_keywords;
|
||||
Set<String> keywords;
|
||||
|
||||
for (List<String>::Element *E = kwors.front(); E; E = E->next()) {
|
||||
keywords.insert(E->get());
|
||||
if (scr->get_language()->is_control_flow_keyword(E->get())) {
|
||||
control_flow_keywords.insert(E->get());
|
||||
} else {
|
||||
keywords.insert(E->get());
|
||||
}
|
||||
}
|
||||
|
||||
int line = 0;
|
||||
@@ -506,6 +511,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
|
||||
Color bg_color = EditorSettings::get_singleton()->get("text_editor/highlighting/background_color");
|
||||
Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color");
|
||||
Color control_flow_keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/control_flow_keyword_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 comment_color = EditorSettings::get_singleton()->get("text_editor/highlighting/comment_color");
|
||||
@@ -529,6 +535,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
col = x0;
|
||||
|
||||
bool prev_is_text = false;
|
||||
bool in_control_flow_keyword = false;
|
||||
bool in_keyword = false;
|
||||
bool in_comment = false;
|
||||
for (int i = 0; i < code.length(); i++) {
|
||||
@@ -547,6 +554,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
|
||||
//make symbol a little visible
|
||||
color = symbol_color;
|
||||
in_control_flow_keyword = false;
|
||||
in_keyword = false;
|
||||
} else if (!prev_is_text && _is_text_char(c)) {
|
||||
int pos = i;
|
||||
@@ -554,16 +562,23 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
while (_is_text_char(code[pos])) {
|
||||
pos++;
|
||||
}
|
||||
String word = code.substr(i, pos - i);
|
||||
if (keywords.has(word)) {
|
||||
|
||||
const String word = code.substr(i, pos - i);
|
||||
|
||||
if (control_flow_keywords.has(word)) {
|
||||
in_control_flow_keyword = true;
|
||||
} else if (keywords.has(word)) {
|
||||
in_keyword = true;
|
||||
}
|
||||
|
||||
} else if (!_is_text_char(c)) {
|
||||
in_control_flow_keyword = false;
|
||||
in_keyword = false;
|
||||
}
|
||||
|
||||
if (in_keyword) {
|
||||
if (in_control_flow_keyword) {
|
||||
color = control_flow_keyword_color;
|
||||
} else if (in_keyword) {
|
||||
color = keyword_color;
|
||||
}
|
||||
}
|
||||
@@ -578,6 +593,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
|
||||
col++;
|
||||
} else {
|
||||
prev_is_text = false;
|
||||
in_control_flow_keyword = false;
|
||||
in_keyword = false;
|
||||
|
||||
if (c == '\n') {
|
||||
|
||||
Reference in New Issue
Block a user