1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Replace XML codeblock spaces with tabs

This commit is contained in:
kobewi
2025-05-17 20:00:17 +02:00
committed by Rémi Verschelde
parent 5dd76968d8
commit 13f642d959
122 changed files with 2407 additions and 2432 deletions

View File

@@ -2395,7 +2395,8 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
}
}
const bool using_tab_indent = int(EDITOR_GET("text_editor/behavior/indent/type")) == 0;
const bool using_space_indent = int(EDITOR_GET("text_editor/behavior/indent/type")) == 1;
const int indent_size = MAX(1, int(EDITOR_GET("text_editor/behavior/indent/size")));
const Ref<Font> doc_font = p_owner_node->get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
const Ref<Font> doc_bold_font = p_owner_node->get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
@@ -2421,7 +2422,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
const Color kbd_bg_color = p_owner_node->get_theme_color(SNAME("kbd_bg_color"), SNAME("EditorHelp"));
const Color param_bg_color = p_owner_node->get_theme_color(SNAME("param_bg_color"), SNAME("EditorHelp"));
String bbcode = p_bbcode.dedent().remove_chars("\t\r").strip_edges();
String bbcode = p_bbcode.dedent().remove_chars("\r").strip_edges();
// Select the correct code examples.
switch ((int)EDITOR_GET("text_editor/help/class_reference_examples")) {
@@ -2661,19 +2662,19 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
const String codeblock_text = bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)).strip_edges();
String codeblock_copy_text = codeblock_text;
if (using_tab_indent) {
// Replace the code block's space indentation with tabs.
if (using_space_indent) {
// Replace the code block's tab indentation with spaces.
StringBuilder builder;
PackedStringArray text_lines = codeblock_copy_text.split("\n");
for (const String &line : text_lines) {
const String stripped_line = line.dedent();
const int space_count = line.length() - stripped_line.length();
const int tab_count = line.length() - stripped_line.length();
if (builder.num_strings_appended() > 0) {
builder.append("\n");
}
if (space_count > 0) {
builder.append(String("\t").repeat(MAX(space_count / 4, 1)) + stripped_line);
if (tab_count > 0) {
builder.append(String(" ").repeat(tab_count * indent_size) + stripped_line);
} else {
builder.append(line);
}