Fix cursor position on indent convert
This commit is contained in:
parent
b474646de0
commit
e7e1d65eb0
1 changed files with 14 additions and 1 deletions
|
@ -285,6 +285,9 @@ void ScriptTextEditor::convert_indent_to_spaces() {
|
||||||
indent += " ";
|
indent += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cursor_line = tx->cursor_get_line();
|
||||||
|
int cursor_column = tx->cursor_get_column();
|
||||||
|
|
||||||
bool changed_indentation = false;
|
bool changed_indentation = false;
|
||||||
for (int i = 0; i < tx->get_line_count(); i++) {
|
for (int i = 0; i < tx->get_line_count(); i++) {
|
||||||
String line = tx->get_line(i);
|
String line = tx->get_line(i);
|
||||||
|
@ -300,6 +303,9 @@ void ScriptTextEditor::convert_indent_to_spaces() {
|
||||||
tx->begin_complex_operation();
|
tx->begin_complex_operation();
|
||||||
changed_indentation = true;
|
changed_indentation = true;
|
||||||
}
|
}
|
||||||
|
if (cursor_line == i && cursor_column > j) {
|
||||||
|
cursor_column += indent_size - 1;
|
||||||
|
}
|
||||||
line = line.left(j) + indent + line.right(j + 1);
|
line = line.left(j) + indent + line.right(j + 1);
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
|
@ -307,6 +313,7 @@ void ScriptTextEditor::convert_indent_to_spaces() {
|
||||||
tx->set_line(i, line);
|
tx->set_line(i, line);
|
||||||
}
|
}
|
||||||
if (changed_indentation) {
|
if (changed_indentation) {
|
||||||
|
tx->cursor_set_column(cursor_column);
|
||||||
tx->end_complex_operation();
|
tx->end_complex_operation();
|
||||||
tx->update();
|
tx->update();
|
||||||
}
|
}
|
||||||
|
@ -323,6 +330,9 @@ void ScriptTextEditor::convert_indent_to_tabs() {
|
||||||
int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size");
|
int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size");
|
||||||
indent_size -= 1;
|
indent_size -= 1;
|
||||||
|
|
||||||
|
int cursor_line = tx->cursor_get_line();
|
||||||
|
int cursor_column = tx->cursor_get_column();
|
||||||
|
|
||||||
bool changed_indentation = false;
|
bool changed_indentation = false;
|
||||||
for (int i = 0; i < tx->get_line_count(); i++) {
|
for (int i = 0; i < tx->get_line_count(); i++) {
|
||||||
String line = tx->get_line(i);
|
String line = tx->get_line(i);
|
||||||
|
@ -342,7 +352,9 @@ void ScriptTextEditor::convert_indent_to_tabs() {
|
||||||
tx->begin_complex_operation();
|
tx->begin_complex_operation();
|
||||||
changed_indentation = true;
|
changed_indentation = true;
|
||||||
}
|
}
|
||||||
|
if (cursor_line == i && cursor_column > j) {
|
||||||
|
cursor_column -= indent_size;
|
||||||
|
}
|
||||||
line = line.left(j - indent_size) + "\t" + line.right(j + 1);
|
line = line.left(j - indent_size) + "\t" + line.right(j + 1);
|
||||||
j = 0;
|
j = 0;
|
||||||
space_count = -1;
|
space_count = -1;
|
||||||
|
@ -355,6 +367,7 @@ void ScriptTextEditor::convert_indent_to_tabs() {
|
||||||
tx->set_line(i, line);
|
tx->set_line(i, line);
|
||||||
}
|
}
|
||||||
if (changed_indentation) {
|
if (changed_indentation) {
|
||||||
|
tx->cursor_set_column(cursor_column);
|
||||||
tx->end_complex_operation();
|
tx->end_complex_operation();
|
||||||
tx->update();
|
tx->update();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue