diff --git a/ui/src/main/java/com/kotcrab/vis/ui/widget/VisTextField.java b/ui/src/main/java/com/kotcrab/vis/ui/widget/VisTextField.java
index <HASH>..<HASH> 100644
--- a/ui/src/main/java/com/kotcrab/vis/ui/widget/VisTextField.java
+++ b/ui/src/main/java/com/kotcrab/vis/ui/widget/VisTextField.java
@@ -437,7 +437,7 @@ public class VisTextField extends Widget implements Disableable, Focusable, Bord
 		} else
 			displayText = newDisplayText;
 
-		layout.setText(font, displayText);
+		layout.setText(font, displayText.toString().replace('\r', ' ').replace('\n', ' '));
 		glyphPositions.clear();
 		float x = 0;
 		if (layout.runs.size > 0) {
@@ -457,6 +457,9 @@ public class VisTextField extends Widget implements Disableable, Focusable, Bord
 		}
 		glyphPositions.add(x);
 
+		visibleTextStart = Math.min(visibleTextStart, glyphPositions.size);
+		visibleTextEnd = MathUtils.clamp(visibleTextEnd, visibleTextStart, glyphPositions.size);
+
 		if (selectionStart > newDisplayText.length()) selectionStart = textLength;
 	}
Fix VisTextField crash when text has newlines (#<I>)

#<I>