Skip to content

Commit

Permalink
Text widget: Remove copy of scroll offset to avoid scroll jump after …
Browse files Browse the repository at this point in the history
…layout

The scroll offset member was not always kept in sync with the element's actual scroll offset. This sometimes caused trouble during re-layout when an old value of scroll offset was applied, causing the text widget contents to jump during layout.

The member seems to serve no good purpose anymore, so we simply remove it. Possibly, the idea was that setting the scroll offset after layout helped restore the scroll offset in case it was temporarily clamped in the middle of formatting. However, this should no longer be happening now that there is more control over scroll clamping behavior.

This change may also have improved IME positioning.
  • Loading branch information
mikke89 committed Oct 28, 2024
1 parent 36af609 commit 2f76544
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
11 changes: 2 additions & 9 deletions Source/Core/Elements/WidgetTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ void WidgetTextInputContext::CommitComposition(StringView composition)
element->SetValue(value);
}

WidgetTextInput::WidgetTextInput(ElementFormControl* _parent) :
internal_dimensions(0, 0), scroll_offset(0, 0), cursor_position(0, 0), cursor_size(0, 0)
WidgetTextInput::WidgetTextInput(ElementFormControl* _parent)
{
keyboard_showed = false;

Expand Down Expand Up @@ -487,9 +486,6 @@ void WidgetTextInput::OnLayout()
UpdateCursorPosition(true);
force_formatting_on_next_layout = false;
}

parent->SetScrollLeft(scroll_offset.x);
parent->SetScrollTop(scroll_offset.y);
}

Element* WidgetTextInput::GetElement() const
Expand Down Expand Up @@ -1155,9 +1151,6 @@ void WidgetTextInput::ShowCursor(bool show, bool move_to_cursor)
parent->SetScrollLeft(minimum_scroll_left);
else if (parent->GetScrollLeft() > cursor_position.x)
parent->SetScrollLeft(cursor_position.x);

scroll_offset.x = parent->GetScrollLeft();
scroll_offset.y = parent->GetScrollTop();
}

SetKeyboardActive(true);
Expand Down Expand Up @@ -1570,7 +1563,7 @@ void WidgetTextInput::SetKeyboardActive(bool active)
if (active)
{
// Activate the keyboard and submit the cursor position and line height to enable clients to adjust the input method editor (IME).
const Vector2f element_offset = parent->GetAbsoluteOffset() - scroll_offset;
const Vector2f element_offset = parent->GetAbsoluteOffset() - Vector2f{parent->GetScrollLeft(), parent->GetScrollTop()};
const Vector2f absolute_cursor_position = element_offset + cursor_position;
system->ActivateKeyboard(absolute_cursor_position, cursor_size.y);
}
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Elements/WidgetTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class WidgetTextInput : public EventListener {
ElementText* text_element;
ElementText* selected_text_element;
Vector2f internal_dimensions;
Vector2f scroll_offset;

using LineList = Vector<Line>;
LineList lines;
Expand Down

0 comments on commit 2f76544

Please sign in to comment.