diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-10-04 18:18:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 18:18:32 +0200 |
commit | adc9500e5497c7427f91d7cbf9985f74cbb3451c (patch) | |
tree | f6675cf49548a32cd5588e642368d04c0b81f293 /scene/gui | |
parent | 87e7f793e4852a6fda6a338b8abd0c5cda38ac25 (diff) | |
parent | fcb102a8265276a59a9c54b85e5b085b1a8b7db9 (diff) |
Merge pull request #53330 from jmb462/fix-bad-caret-position-after-ctrl-x
Fix caret position and viewport centering after deleting line (Ctrl-X)
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/text_edit.cpp | 15 |
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; } |