summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorjmb462 <jmb462@gmail.com>2021-10-02 11:23:36 +0200
committerjmb462 <jmb462@gmail.com>2021-10-04 17:11:20 +0200
commitfcb102a8265276a59a9c54b85e5b085b1a8b7db9 (patch)
tree0b2abec5fec5730d43bb7d0c531c09deaa1dec47 /scene/gui
parent865b62b1cddbb7989bc520eed2d8428c6923fee9 (diff)
Fix caret position and viewport centering after deleting line (Ctrl-X)
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 875049ab4e..57bcbb7c2d 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -5072,10 +5072,12 @@ void TextEdit::_cut_internal() {
}
int cl = get_caret_line();
+ int cc = get_caret_column();
+ int indent_level = get_indent_level(cl);
+ double hscroll = get_h_scroll();
String clipboard = text[cl];
DisplayServer::get_singleton()->clipboard_set(clipboard);
- set_caret_line(cl);
set_caret_column(0);
if (cl == 0 && get_line_count() > 1) {
@@ -5086,6 +5088,17 @@ void TextEdit::_cut_internal() {
set_caret_line(get_caret_line() + 1);
}
+ // Correct the visualy perceived caret column taking care of identation level of the lines.
+ int diff_indent = indent_level - get_indent_level(get_caret_line());
+ cc += diff_indent;
+ if (diff_indent != 0) {
+ cc += diff_indent > 0 ? -1 : 1;
+ }
+
+ // Restore horizontal scroll and caret column modified by the backspace() call.
+ set_h_scroll(hscroll);
+ set_caret_column(cc);
+
cut_copy_line = clipboard;
}