Ported: Highlight control flow keywords with a different color. This makes them easier to distinguish from other keywords.

- Calinou
e905e8f145
This commit is contained in:
Relintai 2023-02-21 13:20:25 +01:00
parent 8eca52fc76
commit c3f01e0b3d
4 changed files with 26 additions and 7 deletions

View File

@ -30,8 +30,8 @@
#include "editor_syntax_highlighter.h"
#include "editor/editor_settings.h"
#include "core/config/project_settings.h"
#include "editor/editor_settings.h"
#include "editor_script_editor.h"
/*** SYNTAX HIGHLIGHTER ****/
@ -143,11 +143,16 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
/* Reserved words. */
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
List<String> keywords;
script->get_language()->get_reserved_words(&keywords);
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
if (script->get_language()->is_control_flow_keyword(E->get())) {
highlighter->add_keyword_color(E->get(), control_flow_keyword_color);
} else {
highlighter->add_keyword_color(E->get(), keyword_color);
}
}
/* Member types. */
const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");

View File

@ -168,13 +168,18 @@ void ShaderTextEditor::_load_theme_settings() {
syntax_highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color"));
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
List<String> keywords;
ShaderLanguage::get_keyword_list(&keywords);
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
if (ShaderLanguage::is_control_flow_keyword(E->get())) {
syntax_highlighter->add_keyword_color(E->get(), control_flow_keyword_color);
} else {
syntax_highlighter->add_keyword_color(E->get(), keyword_color);
}
}
// Colorize built-ins like `COLOR` differently to make them easier
// to distinguish from keywords at a quick glance.

View File

@ -31,8 +31,8 @@
#include "cscript_highlighter.h"
#include "../cscript.h"
#include "../cscript_tokenizer.h"
#include "editor/editor_settings.h"
#include "core/config/project_settings.h"
#include "editor/editor_settings.h"
static bool _is_char(CharType c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
@ -412,7 +412,6 @@ Dictionary CScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
return color_map;
}
String CScriptSyntaxHighlighter::_get_name() const {
return "CScript";
}
@ -492,11 +491,16 @@ void CScriptSyntaxHighlighter::_update_cache() {
/* Reserved words. */
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
List<String> keyword_list;
cscript->get_reserved_words(&keyword_list);
for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
if (cscript->is_control_flow_keyword(E->get())) {
keywords[E->get()] = control_flow_keyword_color;
} else {
keywords[E->get()] = keyword_color;
}
}
/* Comments */
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");

View File

@ -508,11 +508,16 @@ void GDScriptSyntaxHighlighter::_update_cache() {
/* Reserved words. */
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
List<String> keyword_list;
gdscript->get_reserved_words(&keyword_list);
for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
if (gdscript->is_control_flow_keyword(E->get())) {
keywords[E->get()] = control_flow_keyword_color;
} else {
keywords[E->get()] = keyword_color;
}
}
/* Comments */
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");