From 0276e4116035a502ab34a919830d1fe546a4f068 Mon Sep 17 00:00:00 2001 From: Michael Ragazzon Date: Sat, 6 Jul 2024 22:01:45 +0200 Subject: [PATCH] Fix text widget unstable positioning when moving cursor into view In particular, for small text boxes (e.g. lower than line-height), every navigation event would alternate the scroll position between the bottom and the top of the line. --- Source/Core/Elements/WidgetTextInput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Elements/WidgetTextInput.cpp b/Source/Core/Elements/WidgetTextInput.cpp index 7bef25ada..f03c61a38 100644 --- a/Source/Core/Elements/WidgetTextInput.cpp +++ b/Source/Core/Elements/WidgetTextInput.cpp @@ -1143,14 +1143,14 @@ void WidgetTextInput::ShowCursor(bool show, bool move_to_cursor) // Shift the cursor into view. if (move_to_cursor) { - float minimum_scroll_top = (cursor_position.y + cursor_size.y) - GetAvailableHeight(); + float minimum_scroll_top = Math::Min((cursor_position.y + cursor_size.y) - GetAvailableHeight(), cursor_position.y); if (parent->GetScrollTop() < minimum_scroll_top) parent->SetScrollTop(minimum_scroll_top); else if (parent->GetScrollTop() > cursor_position.y) parent->SetScrollTop(cursor_position.y); const bool word_wrap = parent->GetComputedValues().white_space() == Style::WhiteSpace::Prewrap; - float minimum_scroll_left = (cursor_position.x + cursor_size.x) - GetAvailableWidth(); + float minimum_scroll_left = Math::Min((cursor_position.x + cursor_size.x) - GetAvailableWidth(), cursor_position.x); if (word_wrap) parent->SetScrollLeft(0.f); else if (parent->GetScrollLeft() < minimum_scroll_left)