From 2a0b2b696affe6e515115806c92173beca7b3973 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 12 Jan 2024 14:25:37 +0100 Subject: [PATCH] Fixed custom font support in the editor's text editor module. --- .../text_editor/text_editor_settings.cpp | 21 +++++++++++-------- .../text_editor/text_file_editor.cpp | 13 ++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/editor_modules/text_editor/text_editor_settings.cpp b/editor_modules/text_editor/text_editor_settings.cpp index b3fd8bab0d..cec99204db 100644 --- a/editor_modules/text_editor/text_editor_settings.cpp +++ b/editor_modules/text_editor/text_editor_settings.cpp @@ -73,7 +73,9 @@ void TextEditorSettings::remove_opened_file(const int index, ItemList *fileconta for (int i = 0; i < arr.size(); ++i) { Array a = arr[i]; - if (a.size() < 2) { + if (a.size() < 1) { + arr.remove(i); + --i; continue; } @@ -85,14 +87,12 @@ void TextEditorSettings::remove_opened_file(const int index, ItemList *fileconta EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr); - /* Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary()); if (fonts_dict.has(f)) { fonts_dict.erase(f); EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict); } - */ } Array TextEditorSettings::load_opened_files() { @@ -112,23 +112,26 @@ Array TextEditorSettings::load_opened_files() { k.push_back(a[0]); k.push_back(a[1]); - /* - if (fonts_dict.has(a[2])) { - k.push_back(fonts_dict[a[2]]); + if (fonts_dict.has(a[1])) { + k.push_back(fonts_dict[a[1]]); } else { k.push_back("null"); } - */ keys.append(k); } + ERR_PRINT(Variant(keys)); + return keys; } -void TextEditorSettings::store_editor_fonts(const String &file_name, const String &font_path) { +void TextEditorSettings::store_editor_fonts(const String &file_path, const String &font_path) { Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary()); - fonts_dict[file_name] = font_path; + fonts_dict[file_path] = font_path; + + ERR_PRINT(Variant(fonts_dict)); + EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict); } diff --git a/editor_modules/text_editor/text_file_editor.cpp b/editor_modules/text_editor/text_file_editor.cpp index f33ade1b0a..a839b68d39 100644 --- a/editor_modules/text_editor/text_file_editor.cpp +++ b/editor_modules/text_editor/text_file_editor.cpp @@ -186,7 +186,7 @@ void TextFileEditor::_on_font_selected(const String &font_path) { current_editor->set_font(font_path); } - _text_editor_settings->store_editor_fonts(current_file_path.get_file(), font_path); + _text_editor_settings->store_editor_fonts(current_file_path, font_path); } void TextFileEditor::_on_fileitem_pressed(const int index) { @@ -250,14 +250,9 @@ void TextFileEditor::open_file(const String &path, const String &font) { current_file_path = path; TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path); - /* - Ref edf = vanilla_editor->get("custom_fonts/font"); - - //TODO this logic seems wrong - if (font != "null" && edf.is_valid()) { + if (font != "null") { vanilla_editor->set_font(font); } - */ generate_file_item(path, vanilla_editor); @@ -783,11 +778,11 @@ void TextFileEditor::_notification(int p_what) { for (int i = 0; i < opened_files.size(); ++i) { Array opened_file = opened_files[i]; - if (opened_file.size() < 2) { + if (opened_file.size() < 3) { continue; } - open_file(opened_file[0], opened_file[1]); + open_file(opened_file[1], opened_file[2]); } file_list->set_filters(EXTENSIONS);