Skip to content

Fix UI freeze when drag-selecting past the right edge - #609

Open
mgarstenauer wants to merge 1 commit into
AvaloniaUI:masterfrom
garstenauer:fix-ui-freeze-when-drag-selecting
Open

Fix UI freeze when drag-selecting past the right edge#609
mgarstenauer wants to merge 1 commit into
AvaloniaUI:masterfrom
garstenauer:fix-ui-freeze-when-drag-selecting

Conversation

@mgarstenauer

Copy link
Copy Markdown
Contributor

Fixes #606

Problem

The UI will freeze when dragging the selection past the right edge of the text editor. See details in #606.

Cause

The expected behavior is that the scrolling stops when the end of the scroll bar is reached. However, in this case Caret.BringIntoView(5.0) is called, which adds an artificial border around the caret. When this border lies outside of the range of the scroll viewer then TextView.MakeVisible sets an invalid, out-of-range scroll offset. This triggers another ScrollOffsetChanged event with the invalid scroll offset. This causes an endless loop, the drag-selecting/scrolling never stops.

Solution

In TextView.MakeVisible clamp the scroll offset to the allowed range.

public void BringCaretToView()
{
BringCaretToView(0);
BringCaretToView(5.0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In most cases only caret.BringCaretToView() is called, which doesn't guarantee that the caret is visible.

For example (tested in AvaloniaEdit.Demo): On a long line when I press End, the caret jumps to the end of the line. The end of the line is visible, but the caret is just slightly out of view.

⇒ I suggest to make BringCaretToView(5.0) the default.

@mgarstenauer
mgarstenauer force-pushed the fix-ui-freeze-when-drag-selecting branch from da53616 to ffb69fc Compare August 15, 2026 10:29
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.

Infinite UI freeze when drag-selecting past the right edge (regression from #500)

1 participant