Browse Source

Merge pull request #51078 from nekomatata/code-editor-theme-change-optimization

Optimize theme change in code editor
Rémi Verschelde 4 years ago
parent
commit
fd0775398b
2 changed files with 15 additions and 0 deletions
  1. 12 0
      editor/code_editor.cpp
  2. 3 0
      editor/code_editor.h

+ 12 - 0
editor/code_editor.cpp

@@ -31,6 +31,7 @@
 #include "code_editor.h"
 
 #include "core/input/input.h"
+#include "core/object/message_queue.h"
 #include "core/os/keyboard.h"
 #include "core/string/string_builder.h"
 #include "editor/editor_scale.h"
@@ -1567,6 +1568,17 @@ void CodeTextEditor::_update_font() {
 }
 
 void CodeTextEditor::_on_settings_change() {
+	if (settings_changed) {
+		return;
+	}
+
+	settings_changed = true;
+	MessageQueue::get_singleton()->push_callable(callable_mp(this, &CodeTextEditor::_apply_settings_change));
+}
+
+void CodeTextEditor::_apply_settings_change() {
+	settings_changed = false;
+
 	_update_text_editor_theme();
 	_update_font();
 

+ 3 - 0
editor/code_editor.h

@@ -162,7 +162,10 @@ class CodeTextEditor : public VBoxContainer {
 	int error_line;
 	int error_column;
 
+	bool settings_changed = false;
+
 	void _on_settings_change();
+	void _apply_settings_change();
 
 	void _update_text_editor_theme();
 	void _update_font();