Skip to content

TextBoxView: fix crash during large selection with pending background layout#11461

Open
etvorun wants to merge 1 commit intodotnet:mainfrom
etvorun:fix/textboxview-background-layout-crash
Open

TextBoxView: fix crash during large selection with pending background layout#11461
etvorun wants to merge 1 commit intodotnet:mainfrom
etvorun:fix/textboxview-background-layout-crash

Conversation

@etvorun
Copy link

@etvorun etvorun commented Feb 18, 2026

Summary

Fixes a TextBoxView crash path that can occur during large-text selection when layout is still in background progress.

What changed

  • Added defensive clamping in GetLineIndexFromOffset when the requested offset is beyond the currently measured region.
  • Return the last measured line index in this transitional background-layout window.
  • Removed fragile Invariant.Assert(Contains(position)) checks from affected text-view operations that can be reached during transitional layout timing.

Why

TextBoxView uses incremental/time-sliced layout. During that window, selection/highlight paths can request offsets beyond the measured _lineMetrics range. The defensive path prevents assertion/fail-fast and preserves expected behavior.

Validation

  • Ported patch applied to TextBoxView.cs only.
  • File diagnostics checked locally (No errors found for the modified file).

Fixes #11460

Microsoft Reviewers: Open in CodeFlow

@etvorun etvorun requested review from a team and Copilot February 18, 2026 22:36
@dotnet-policy-service dotnet-policy-service bot added the PR metadata: Label to tag PRs, to facilitate with triage label Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in TextBoxView that occurs during large text selection when incremental background layout is still in progress. The crash happened because GetLineIndexFromOffset assumed all requested offsets were within the currently measured _lineMetrics range, but during time-sliced layout, selection/highlight operations can request offsets beyond what has been measured so far.

Changes:

  • Added defensive clamping in GetLineIndexFromOffset to return the last measured line index when offsets exceed the measured region during background layout
  • Removed overly strict Contains(position) assertions from several ITextView methods that can be legitimately called during transitional layout states
  • Added documentation explaining the background layout handling in GetLineIndexFromOffset

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TextBoxView] Crash during large selection while background layout is incomplete

2 participants