From 3efb28078e55f33f3b794e784065056cb192e061 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sun, 13 Aug 2023 18:20:52 -0600 Subject: [PATCH] KissInputText insert actual newlines when wrapping --- src/kiss_flixel/KissInputText.hx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/kiss_flixel/KissInputText.hx b/src/kiss_flixel/KissInputText.hx index beb5e4c..6776003 100644 --- a/src/kiss_flixel/KissInputText.hx +++ b/src/kiss_flixel/KissInputText.hx @@ -377,6 +377,18 @@ class KissInputText extends FlxText if (newText.length > 0 && (maxLength == 0 || (text.length + newText.length) < maxLength)) { + // Remove previous lines from the textField's text when checking for overflow: + var textFieldText = textField.text; + textField.text = textField.text.substr(0, caretIndex).split("\n").pop(); + + if (textField.textWidth > (width - 4 - textField.textHeight)) { + textField.text = textFieldText; + text = insertSubstring(text, "\n", caretIndex); + caretIndex++; + } else { + textField.text = textFieldText; + } + text = insertSubstring(text, newText, caretIndex); caretIndex++; onChange(INPUT_ACTION); @@ -498,7 +510,7 @@ class KissInputText extends FlxText lastW = 0; continue; } - textW = textField.textWidth; // count up total text width + textW = textField.textWidth; // count up total text width of this line _charBoundaries[i].x = magicX + lastW; // place x at end of last character _charBoundaries[i].y = magicY + lastH; // place y at end of last line _charBoundaries[i].width = (textW - lastW); // place width at (width so far) minus (last char's end point)