From 2f76544c06b882acbf3028f50d89a9e0214a8ce5 Mon Sep 17 00:00:00 2001 From: Michael Ragazzon Date: Mon, 28 Oct 2024 23:22:35 +0100 Subject: [PATCH] Text widget: Remove copy of scroll offset to avoid scroll jump after 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. --- Source/Core/Elements/WidgetTextInput.cpp | 11 ++--------- Source/Core/Elements/WidgetTextInput.h | 1 - 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Source/Core/Elements/WidgetTextInput.cpp b/Source/Core/Elements/WidgetTextInput.cpp index ea99607dd..0056ad009 100644 --- a/Source/Core/Elements/WidgetTextInput.cpp +++ b/Source/Core/Elements/WidgetTextInput.cpp @@ -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; @@ -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 @@ -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); @@ -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); } diff --git a/Source/Core/Elements/WidgetTextInput.h b/Source/Core/Elements/WidgetTextInput.h index 4fc6f55b3..bed9bf615 100644 --- a/Source/Core/Elements/WidgetTextInput.h +++ b/Source/Core/Elements/WidgetTextInput.h @@ -246,7 +246,6 @@ class WidgetTextInput : public EventListener { ElementText* text_element; ElementText* selected_text_element; Vector2f internal_dimensions; - Vector2f scroll_offset; using LineList = Vector; LineList lines;