Skip to content

Commit

Permalink
Fixed custom font support in the editor's text editor module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed Jan 12, 2024
1 parent b9a0b82 commit 2a0b2b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
21 changes: 12 additions & 9 deletions editor_modules/text_editor/text_editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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() {
Expand All @@ -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);
}

Expand Down
13 changes: 4 additions & 9 deletions editor_modules/text_editor/text_file_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Font> 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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2a0b2b6

Please sign in to comment.