private void updateCursorAndLayout() { Placeholder.Font = Placeholder.Font.With(size: CalculatedTextSize); textUpdateScheduler.Update(); float cursorPos = 0; if (text.Length > 0) { cursorPos = getPositionAt(selectionLeft); } float cursorPosEnd = getPositionAt(selectionEnd); float?selectionWidth = null; if (selectionLength > 0) { selectionWidth = getPositionAt(selectionRight) - cursorPos; } float cursorRelativePositionAxesInBox = (cursorPosEnd - textContainerPosX) / DrawWidth; //we only want to reposition the view when the cursor reaches near the extremities. if (cursorRelativePositionAxesInBox < 0.1 || cursorRelativePositionAxesInBox > 0.9) { textContainerPosX = cursorPosEnd - DrawWidth / 2 + LeftRightPadding * 2; } textContainerPosX = Math.Clamp(textContainerPosX, 0, Math.Max(0, TextFlow.DrawWidth - DrawWidth + LeftRightPadding * 2)); TextContainer.MoveToX(LeftRightPadding - textContainerPosX, 300, Easing.OutExpo); if (HasFocus) { caret.DisplayAt(new Vector2(cursorPos, 0), selectionWidth); } if (textAtLastLayout != text) { Current.Value = text; } if (textAtLastLayout.Length == 0 || text.Length == 0) { if (text.Length == 0) { Placeholder.Show(); } else { Placeholder.Hide(); } } textAtLastLayout = text; }