Skip to content

Win multilinetext scroll to bottom#4276

Merged
freakboy3742 merged 7 commits intobeeware:mainfrom
albuszheng:win-multilinetext-scroll-to-bottom
Apr 1, 2026
Merged

Win multilinetext scroll to bottom#4276
freakboy3742 merged 7 commits intobeeware:mainfrom
albuszheng:win-multilinetext-scroll-to-bottom

Conversation

@albuszheng
Copy link
Copy Markdown
Contributor

@albuszheng albuszheng commented Mar 27, 2026

Implemented a workaround using the underlying Win32 SendMessage method. Currently, the scroll_to_bottom() method in the MultilineTextInput sends the explicit low-level message to scroll, rather than ScrollToCaret, based on the solution suggested here.

The scroll_to_bottom will no longer jump up and down in MultilineTextInput running on Windows; it will consistently move to the bottom of the widget.

Fixes #3872

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@albuszheng
Copy link
Copy Markdown
Contributor Author

The test failed on (windows-latest, 3.12) due to "Unable to download artifact(s)". I don't think it is related to the changes of the code.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR - this looks great as an implementation.

I've flagged one minor problem inline; the other issue is the lack of a test. We need to have a test for this behavior to make sure it doesn't reoccur.

The testbed folder already contains a test that exercises scroll_to_bottom(); as part of this change, we need to add an extra piece to that test so that the call to scroll_to_bottom() is done twice in a row, confirming that the scroll position doesn't change between the two calls. This test should fail on the current main code; but will pass with your change applied.

The testbed suite is currently failing on Linux machines - that's unrelated to your changes. GitHub has changed something recently; we're still trying to work out what that is.

): # pragma: nocover
parent.OnMouseWheel(e)
e.Handled = True
e.Handled = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a duplicate.

Suggested change
e.Handled = True

@freakboy3742
Copy link
Copy Markdown
Member

FYI: I've just resolved the issue with Linux testing, and re-run the tests that were failing.

@albuszheng
Copy link
Copy Markdown
Contributor Author

I found out that the current test case in the testbed will not fail with consecutive scroll_to_bottom calls on the current main code. Is there a way to access the scroll bar position from the multilinetextinput natively?

@freakboy3742
Copy link
Copy Markdown
Member

I found out that the current test case in the testbed will not fail with consecutive scroll_to_bottom calls on the current main code. Is there a way to access the scroll bar position from the multilinetextinput natively?

That's what the calls to probe.vertical_scroll_position are exposing - the internal numerical position of the scroll. My guess is that the test needs to assert that the value of probe.vertical_scroll_position doesn't change before and after the second call to scroll_to_bottom().

@albuszheng
Copy link
Copy Markdown
Contributor Author

I have added an additional test case for the multilinetextinput widget to check that the vertical_scroll_position value stays the same when scroll_to_bottom() is called consecutively.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test update! I've pushed a couple of minor tweaks, but otherwise, this looks great - thanks for the PR!

@@ -0,0 +1 @@
`scroll_to_bottom()` now behave correctly and consistently for MultilineTextInput in Windows, and new test case is added.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change note should be a user-facing description of the feature/bugfix, not a description of the code change:

Suggested change
`scroll_to_bottom()` now behave correctly and consistently for MultilineTextInput in Windows, and new test case is added.
Calling `scroll_to_bottom()` on a `MultilineTextInput` that is already at the bottom of the scroll area no longer causes a "bounce" in the scroll position.

Comment on lines +98 to +101
# Invoke the scroll_to_bottom again while the vertical scroll position of the
# document stay at the bottom. This is to make sure repeated call of
# scroll_to_bottom method would not make the vertical scroll position change up and
# down.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a specific bug involved, it can be helpful to reference that bug.

# scroll_to_bottom method would not make the vertical scroll position change up and
# down.
widget.scroll_to_bottom()
assert probe.vertical_scroll_position == first_vertical_scroll_pos
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth adding a "wait for scroll position" here to make sure any scroll that does occur actually completes:

Suggested change
assert probe.vertical_scroll_position == first_vertical_scroll_pos
await probe.wait_for_scroll_position()
assert probe.vertical_scroll_position == first_vertical_scroll_pos

@freakboy3742 freakboy3742 merged commit 85e0e4d into beeware:main Apr 1, 2026
116 of 117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scroll_to_bottom MultilineTextInput behavior in Windows

2 participants