Răsfoiți Sursa

Add comment highlighting to script thumbnails

(cherry picked from commit 46e0161737d7a701813c9e012f4cc6a9304875f2)
Michael Alexsander 4 ani în urmă
părinte
comite
ae99339e9f
1 a modificat fișierele cu 33 adăugiri și 17 ștergeri
  1. 33 17
      editor/plugins/editor_preview_plugins.cpp

+ 33 - 17
editor/plugins/editor_preview_plugins.cpp

@@ -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 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");
 
 	img->lock();
 
@@ -542,6 +543,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
 
 	bool prev_is_text = false;
 	bool in_keyword = false;
+	bool in_comment = false;
 	for (int i = 0; i < code.length(); i++) {
 
 		CharType c = code[i];
@@ -549,27 +551,37 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
 			if (col < thumbnail_size) {
 				Color color = text_color;
 
-				if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
-					//make symbol a little visible
-					color = symbol_color;
-					in_keyword = false;
-				} else if (!prev_is_text && _is_text_char(c)) {
-					int pos = i;
+				if (c == '#') {
+					in_comment = true;
+				}
 
-					while (_is_text_char(code[pos])) {
-						pos++;
+				if (in_comment) {
+					color = comment_color;
+				} else {
+					if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) {
+						//make symbol a little visible
+						color = symbol_color;
+						in_keyword = false;
+					} else if (!prev_is_text && _is_text_char(c)) {
+						int pos = i;
+
+						while (_is_text_char(code[pos])) {
+							pos++;
+						}
+						String word = code.substr(i, pos - i);
+						if (keywords.has(word)) {
+							in_keyword = true;
+						}
+
+					} else if (!_is_text_char(c)) {
+						in_keyword = false;
 					}
-					String word = code.substr(i, pos - i);
-					if (keywords.has(word))
-						in_keyword = true;
 
-				} else if (!_is_text_char(c)) {
-					in_keyword = false;
+					if (in_keyword) {
+						color = keyword_color;
+					}
 				}
 
-				if (in_keyword)
-					color = keyword_color;
-
 				Color ul = color;
 				ul.a *= 0.5;
 				img->set_pixel(col, y0 + line * 2, bg_color.blend(ul));
@@ -577,21 +589,25 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2
 
 				prev_is_text = _is_text_char(c);
 			}
+			col++;
 		} else {
 
 			prev_is_text = false;
 			in_keyword = false;
 
 			if (c == '\n') {
+				in_comment = false;
+
 				col = x0;
 				line++;
 				if (line >= available_height / 2)
 					break;
 			} else if (c == '\t') {
 				col += 3;
+			} else {
+				col++;
 			}
 		}
-		col++;
 	}
 
 	img->unlock();