summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/code_editor.cpp108
-rw-r--r--editor/code_editor.h3
-rw-r--r--editor/plugins/script_editor_plugin.cpp26
-rw-r--r--editor/plugins/script_editor_plugin.h4
-rw-r--r--editor/plugins/script_text_editor.cpp14
-rw-r--r--editor/plugins/script_text_editor.h3
-rw-r--r--editor/plugins/text_editor.cpp14
-rw-r--r--editor/plugins/text_editor.h3
8 files changed, 22 insertions, 153 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 91ccede26d..b188e1faca 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -902,6 +902,9 @@ void CodeTextEditor::_line_col_changed() {
sb.append(" : ");
sb.append(itos(positional_column + 1).lpad(3));
+ sb.append(" | ");
+ sb.append(text_editor->is_indent_using_spaces() ? "Spaces" : "Tabs");
+
line_and_col_txt->set_text(sb.as_string());
if (find_replace_bar) {
@@ -1142,111 +1145,6 @@ void CodeTextEditor::insert_final_newline() {
}
}
-void CodeTextEditor::convert_indent_to_spaces() {
- int indent_size = EDITOR_GET("text_editor/behavior/indent/size");
- String indent = String(" ").repeat(indent_size);
-
- Vector<int> cursor_columns;
- cursor_columns.resize(text_editor->get_caret_count());
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- cursor_columns.write[c] = text_editor->get_caret_column(c);
- }
-
- bool changed_indentation = false;
- for (int i = 0; i < text_editor->get_line_count(); i++) {
- String line = text_editor->get_line(i);
-
- if (line.length() <= 0) {
- continue;
- }
-
- int j = 0;
- while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) {
- if (line[j] == '\t') {
- if (!changed_indentation) {
- text_editor->begin_complex_operation();
- changed_indentation = true;
- }
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- if (text_editor->get_caret_line(c) == i && text_editor->get_caret_column(c) > j) {
- cursor_columns.write[c] += indent_size - 1;
- }
- }
- line = line.left(j) + indent + line.substr(j + 1);
- }
- j++;
- }
- if (changed_indentation) {
- text_editor->set_line(i, line);
- }
- }
- if (changed_indentation) {
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- text_editor->set_caret_column(cursor_columns[c], c == 0, c);
- }
- text_editor->merge_overlapping_carets();
- text_editor->end_complex_operation();
- text_editor->queue_redraw();
- }
-}
-
-void CodeTextEditor::convert_indent_to_tabs() {
- int indent_size = EDITOR_GET("text_editor/behavior/indent/size");
- indent_size -= 1;
-
- Vector<int> cursor_columns;
- cursor_columns.resize(text_editor->get_caret_count());
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- cursor_columns.write[c] = text_editor->get_caret_column(c);
- }
-
- bool changed_indentation = false;
- for (int i = 0; i < text_editor->get_line_count(); i++) {
- String line = text_editor->get_line(i);
-
- if (line.length() <= 0) {
- continue;
- }
-
- int j = 0;
- int space_count = -1;
- while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) {
- if (line[j] != '\t') {
- space_count++;
-
- if (space_count == indent_size) {
- if (!changed_indentation) {
- text_editor->begin_complex_operation();
- changed_indentation = true;
- }
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- if (text_editor->get_caret_line(c) == i && text_editor->get_caret_column(c) > j) {
- cursor_columns.write[c] -= indent_size;
- }
- }
- line = line.left(j - indent_size) + "\t" + line.substr(j + 1);
- j = 0;
- space_count = -1;
- }
- } else {
- space_count = -1;
- }
- j++;
- }
- if (changed_indentation) {
- text_editor->set_line(i, line);
- }
- }
- if (changed_indentation) {
- for (int c = 0; c < text_editor->get_caret_count(); c++) {
- text_editor->set_caret_column(cursor_columns[c], c == 0, c);
- }
- text_editor->merge_overlapping_carets();
- text_editor->end_complex_operation();
- text_editor->queue_redraw();
- }
-}
-
void CodeTextEditor::convert_case(CaseStyle p_case) {
if (!text_editor->has_selection()) {
return;
diff --git a/editor/code_editor.h b/editor/code_editor.h
index 343720637b..a83bb96771 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -222,9 +222,6 @@ public:
void trim_trailing_whitespace();
void insert_final_newline();
- void convert_indent_to_spaces();
- void convert_indent_to_tabs();
-
enum CaseStyle {
UPPER,
LOWER,
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 0e01b11028..c605844728 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -944,11 +944,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
se->insert_final_newline();
if (convert_indent_on_save) {
- if (use_space_indentation) {
- se->convert_indent_to_spaces();
- } else {
- se->convert_indent_to_tabs();
- }
+ se->convert_indent();
}
Ref<TextFile> text_file = scr;
@@ -1299,11 +1295,7 @@ void ScriptEditor::_menu_option(int p_option) {
current->insert_final_newline();
if (convert_indent_on_save) {
- if (use_space_indentation) {
- current->convert_indent_to_spaces();
- } else {
- current->convert_indent_to_tabs();
- }
+ current->convert_indent();
}
Ref<Resource> resource = current->get_edited_resource();
@@ -2451,11 +2443,7 @@ void ScriptEditor::save_current_script() {
current->insert_final_newline();
if (convert_indent_on_save) {
- if (use_space_indentation) {
- current->convert_indent_to_spaces();
- } else {
- current->convert_indent_to_tabs();
- }
+ current->convert_indent();
}
Ref<Resource> resource = current->get_edited_resource();
@@ -2499,11 +2487,7 @@ void ScriptEditor::save_all_scripts() {
}
if (convert_indent_on_save) {
- if (use_space_indentation) {
- se->convert_indent_to_spaces();
- } else {
- se->convert_indent_to_tabs();
- }
+ se->convert_indent();
}
if (trim_trailing_whitespace_on_save) {
@@ -2730,7 +2714,6 @@ void ScriptEditor::_editor_settings_changed() {
trim_trailing_whitespace_on_save = EDITOR_GET("text_editor/behavior/files/trim_trailing_whitespace_on_save");
convert_indent_on_save = EDITOR_GET("text_editor/behavior/files/convert_indent_on_save");
- use_space_indentation = EDITOR_GET("text_editor/behavior/indent/type");
members_overview_enabled = EDITOR_GET("text_editor/script_list/show_members_overview");
help_overview_enabled = EDITOR_GET("text_editor/help/show_help_index");
@@ -4081,7 +4064,6 @@ ScriptEditor::ScriptEditor() {
edit_pass = 0;
trim_trailing_whitespace_on_save = EDITOR_GET("text_editor/behavior/files/trim_trailing_whitespace_on_save");
convert_indent_on_save = EDITOR_GET("text_editor/behavior/files/convert_indent_on_save");
- use_space_indentation = EDITOR_GET("text_editor/behavior/indent/type");
ScriptServer::edit_request_func = _open_script_request;
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 10dfe0f199..5cbe56b68b 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -169,8 +169,7 @@ public:
virtual void clear_executing_line() = 0;
virtual void trim_trailing_whitespace() = 0;
virtual void insert_final_newline() = 0;
- virtual void convert_indent_to_spaces() = 0;
- virtual void convert_indent_to_tabs() = 0;
+ virtual void convert_indent() = 0;
virtual void ensure_focus() = 0;
virtual void tag_saved_version() = 0;
virtual void reload(bool p_soft) {}
@@ -390,7 +389,6 @@ class ScriptEditor : public PanelContainer {
bool open_textfile_after_create = true;
bool trim_trailing_whitespace_on_save;
- bool use_space_indentation;
bool convert_indent_on_save;
void _goto_script_line2(int p_line);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 9e10eddd5b..978f1f56a5 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -378,12 +378,8 @@ void ScriptTextEditor::insert_final_newline() {
code_editor->insert_final_newline();
}
-void ScriptTextEditor::convert_indent_to_spaces() {
- code_editor->convert_indent_to_spaces();
-}
-
-void ScriptTextEditor::convert_indent_to_tabs() {
- code_editor->convert_indent_to_tabs();
+void ScriptTextEditor::convert_indent() {
+ code_editor->get_text_editor()->convert_indent();
}
void ScriptTextEditor::tag_saved_version() {
@@ -1282,10 +1278,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
trim_trailing_whitespace();
} break;
case EDIT_CONVERT_INDENT_TO_SPACES: {
- convert_indent_to_spaces();
+ tx->set_indent_using_spaces(true);
+ convert_indent();
} break;
case EDIT_CONVERT_INDENT_TO_TABS: {
- convert_indent_to_tabs();
+ tx->set_indent_using_spaces(false);
+ convert_indent();
} break;
case EDIT_PICK_COLOR: {
color_panel->popup();
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 1b986401c2..5e167af51a 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -222,8 +222,7 @@ public:
virtual void ensure_focus() override;
virtual void trim_trailing_whitespace() override;
virtual void insert_final_newline() override;
- virtual void convert_indent_to_spaces() override;
- virtual void convert_indent_to_tabs() override;
+ virtual void convert_indent() override;
virtual void tag_saved_version() override;
virtual void goto_line(int p_line, bool p_with_error = false) override;
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index 174588b92e..7a76e4f989 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -288,12 +288,8 @@ void TextEditor::insert_final_newline() {
code_editor->insert_final_newline();
}
-void TextEditor::convert_indent_to_spaces() {
- code_editor->convert_indent_to_spaces();
-}
-
-void TextEditor::convert_indent_to_tabs() {
- code_editor->convert_indent_to_tabs();
+void TextEditor::convert_indent() {
+ code_editor->get_text_editor()->convert_indent();
}
void TextEditor::tag_saved_version() {
@@ -419,10 +415,12 @@ void TextEditor::_edit_option(int p_op) {
trim_trailing_whitespace();
} break;
case EDIT_CONVERT_INDENT_TO_SPACES: {
- convert_indent_to_spaces();
+ tx->set_indent_using_spaces(true);
+ convert_indent();
} break;
case EDIT_CONVERT_INDENT_TO_TABS: {
- convert_indent_to_tabs();
+ tx->set_indent_using_spaces(false);
+ convert_indent();
} break;
case EDIT_TO_UPPERCASE: {
_convert_case(CodeTextEditor::UPPER);
diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h
index d9f5222e90..0c218e9e0c 100644
--- a/editor/plugins/text_editor.h
+++ b/editor/plugins/text_editor.h
@@ -131,8 +131,7 @@ public:
virtual void clear_executing_line() override;
virtual void trim_trailing_whitespace() override;
virtual void insert_final_newline() override;
- virtual void convert_indent_to_spaces() override;
- virtual void convert_indent_to_tabs() override;
+ virtual void convert_indent() override;
virtual void ensure_focus() override;
virtual void tag_saved_version() override;
virtual void update_settings() override;