summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-11-11 22:32:17 +0100
committerGitHub <noreply@github.com>2020-11-11 22:32:17 +0100
commit8344d27276da130c0cec0398b98305bd37d67ca0 (patch)
tree472142c886a4d455fb9239faf6e48e3ae08a68e5
parent2a0debd0779337154dc6b0a5ad1113647402d43e (diff)
parent87fb2bde0cb9cedd02347095438ed0a75e5063d1 (diff)
Merge pull request #43451 from timothyqiu/move-line-cursor
Keep cursor relative position after move lines up/down in text editor
-rw-r--r--editor/code_editor.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 236d1e884e..3182bca0eb 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -1138,6 +1138,7 @@ void CodeTextEditor::move_lines_up() {
int from_col = text_editor->get_selection_from_column();
int to_line = text_editor->get_selection_to_line();
int to_column = text_editor->get_selection_to_column();
+ int cursor_line = text_editor->cursor_get_line();
for (int i = from_line; i <= to_line; i++) {
int line_id = i;
@@ -1155,7 +1156,9 @@ void CodeTextEditor::move_lines_up() {
}
int from_line_up = from_line > 0 ? from_line - 1 : from_line;
int to_line_up = to_line > 0 ? to_line - 1 : to_line;
+ int cursor_line_up = cursor_line > 0 ? cursor_line - 1 : cursor_line;
text_editor->select(from_line_up, from_col, to_line_up, to_column);
+ text_editor->cursor_set_line(cursor_line_up);
} else {
int line_id = text_editor->cursor_get_line();
int next_id = line_id - 1;
@@ -1181,6 +1184,7 @@ void CodeTextEditor::move_lines_down() {
int from_col = text_editor->get_selection_from_column();
int to_line = text_editor->get_selection_to_line();
int to_column = text_editor->get_selection_to_column();
+ int cursor_line = text_editor->cursor_get_line();
for (int i = to_line; i >= from_line; i--) {
int line_id = i;
@@ -1198,7 +1202,9 @@ void CodeTextEditor::move_lines_down() {
}
int from_line_down = from_line < text_editor->get_line_count() ? from_line + 1 : from_line;
int to_line_down = to_line < text_editor->get_line_count() ? to_line + 1 : to_line;
+ int cursor_line_down = cursor_line < text_editor->get_line_count() ? cursor_line + 1 : cursor_line;
text_editor->select(from_line_down, from_col, to_line_down, to_column);
+ text_editor->cursor_set_line(cursor_line_down);
} else {
int line_id = text_editor->cursor_get_line();
int next_id = line_id + 1;