From f6beaff43a3083c7f8d9350cbca3877e2920681b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 13 Feb 2023 14:37:20 +0100 Subject: [PATCH] Fixed a multiline text field's cursor not returning to the default position when the last character is removed --- CHANGELOG.md | 1 + MLEM/Input/TextInput.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ee35a..9e88510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Fixes Fixes - Fixed images not updating their hidden state properly when the displayed texture changes - Fixed control characters being included in TextField +- Fixed a multiline text field's cursor not returning to the default position when the last character is removed ## 6.1.0 diff --git a/MLEM/Input/TextInput.cs b/MLEM/Input/TextInput.cs index 98287f3..464835d 100644 --- a/MLEM/Input/TextInput.cs +++ b/MLEM/Input/TextInput.cs @@ -512,6 +512,14 @@ namespace MLEM.Input { private void UpdateCaretData() { if (this.splitText != null) { + // the code below will never execute if our text is empty, so reset our caret position fully + if (this.splitText.Length <= 0) { + this.caretLine = 0; + this.caretPosInLine = 0; + this.caretDrawOffset = 0; + return; + } + var line = 0; var index = 0; for (var d = 0; d < this.splitText.Length; d++) {