Skip to content

Commit

Permalink
Fix text widget unstable positioning when moving cursor into view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikke89 committed Jul 7, 2024
1 parent f084efb commit 0276e41
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Elements/WidgetTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0276e41

Please sign in to comment.