2
0
Эх сурвалжийг харах

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.
Michael Ragazzon 1 жил өмнө
parent
commit
2f76544c06

+ 2 - 9
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);
 		}

+ 0 - 1
Source/Core/Elements/WidgetTextInput.h

@@ -246,7 +246,6 @@ private:
 	ElementText* text_element;
 	ElementText* selected_text_element;
 	Vector2f internal_dimensions;
-	Vector2f scroll_offset;
 
 	using LineList = Vector<Line>;
 	LineList lines;