Repository navigation
Return empty text bounds for zero-length ranges - #22344
Conversation
Exercise empty ranges at interior and CRLF boundaries using real text layouts, and retain checks for completed-line geometry and existing negative-range behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Return empty geometry for zero-length requests and stop traversing lines when the remaining range is empty. Keep negative-range behavior and TextLine validation unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NuGet packagesThe packages for this pull request have been published (workflow run):
|
Gillibald
left a comment
There was a problem hiding this comment.
I think we should change GetTextBounds to return an empty rect for an empty range instead of throwing. That also fixes the issue but for all consumers of that API. How is this issue triggered in a real world application?
Expect no text bounds for zero-length ranges at caret and CRLF line boundaries. Retain checks for normal nonempty geometry. Before the fix, the TextLine suite has 8 failures and 81 passes, with all failures throwing for textLength = 0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle zero-length ranges in TextLineImpl.GetTextBounds so all consumers share the empty bounds contract. Remove the TextLayout-only guards and document the result. Negative-length behavior is unchanged. Verified 168 passing TextLine/TextLayout tests, with one existing profiling test skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Moved the fix to TextLineImpl.GetTextBounds, returning an empty bounds collection for zero-length requests, and removed the TextLayout guards. The TextLine/TextLayout suites pass 168 tests with one existing skip. The real-app report came through SelectableTextBlock rendering, but the reporter's exact text and selection sequence is unknown. Ordinary CRLF rendering probes didn't reproduce it; the confirmed reproducer is the zero-length public API call. |
* Add regression tests for empty text layout ranges Exercise empty ranges at interior and CRLF boundaries using real text layouts, and retain checks for completed-line geometry and existing negative-range behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Handle empty ranges in TextLayout hit testing Return empty geometry for zero-length requests and stop traversing lines when the remaining range is empty. Keep negative-range behavior and TextLine validation unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add direct TextLine empty range regressions Expect no text bounds for zero-length ranges at caret and CRLF line boundaries. Retain checks for normal nonempty geometry. Before the fix, the TextLine suite has 8 failures and 81 passes, with all failures throwing for textLength = 0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Return no text bounds for empty ranges Handle zero-length ranges in TextLineImpl.GetTextBounds so all consumers share the empty bounds contract. Remove the TextLayout-only guards and document the result. Negative-length behavior is unchanged. Verified 168 passing TextLine/TextLayout tests, with one existing profiling test skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: adirh <27368554+adirh3@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add regression tests for empty text layout ranges Exercise empty ranges at interior and CRLF boundaries using real text layouts, and retain checks for completed-line geometry and existing negative-range behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Handle empty ranges in TextLayout hit testing Return empty geometry for zero-length requests and stop traversing lines when the remaining range is empty. Keep negative-range behavior and TextLine validation unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add direct TextLine empty range regressions Expect no text bounds for zero-length ranges at caret and CRLF line boundaries. Retain checks for normal nonempty geometry. Before the fix, the TextLine suite has 8 failures and 81 passes, with all failures throwing for textLength = 0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Return no text bounds for empty ranges Handle zero-length ranges in TextLineImpl.GetTextBounds so all consumers share the empty bounds contract. Remove the TextLayout-only guards and document the result. Negative-length behavior is unchanged. Verified 168 passing TextLine/TextLayout tests, with one existing profiling test skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: adirh <27368554+adirh3@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What does the pull request do?
Make
TextLine.GetTextBoundsreturn an empty bounds collection for zero-length requests, protecting every consumer of the API.What is the current behavior?
HitTestTextRange(1, 0)on"abc", andHitTestTextRange(3, 0)on"a\r\nb\r\n", throwArgumentOutOfRangeExceptionwithParamName="textLength"instead of returning empty geometry.Reported exception
An anonymized report from an application using Avalonia 12.1.2 on Windows x64 and .NET 11.0.0-rc.1.26425.128:
This report motivated the investigation; the tests establish the direct empty-range API defect, not the reporter's original rendering sequence.
How was the solution implemented?
Return an empty bounds collection in
TextLineImpl.GetTextBoundsfor a zero-length request, as requested in review, and document that result onTextLine. Remove theTextLayout-specific guards. Negative-length handling is unchanged.Tests
Direct
TextLinetests cover eight zero-length cases at caret and CRLF boundaries, plus three nonempty geometry/run-bound checks. The existingTextLayoutempty-range, completed-line, and negative-length regressions remain. Each test-only commit precedes its implementation commit.The new direct
TextLineregressions produce eightArgumentOutOfRangeExceptionfailures before the lower-API fix, even with the earlier layout-only guards. After the fix, the committedTextLineandTextLayoutsuites pass 168 tests, with one existing profiling-only skip.The confirmed reproducer is the direct zero-length public API call. Three ordinary CRLF
SelectableTextBlockselection-rendering probes also passed with the original throwing implementation. The original reporter's text/selection/input sequence remains unknown; this PR does not claim to reproduce that exact UI trigger.Breaking changes
No signature changes. Zero-length bounds queries now return an empty collection instead of throwing.
AI-assisted contribution. The submitting author will handle review feedback.