Skip to content

fix: clamp widthUntilLineNumberEnd to prevent negative Rect width#301899

Draft
bryanchen-d wants to merge 1 commit intomainfrom
brchen/fix-gutter-indicator-rect-error
Draft

fix: clamp widthUntilLineNumberEnd to prevent negative Rect width#301899
bryanchen-d wants to merge 1 commit intomainfrom
brchen/fix-gutter-indicator-rect-error

Conversation

@bryanchen-d
Copy link
Contributor

When pillRect.width < idealIconAreaWidth (22px) and lineNumbersWidth is 0, the expression pillRect.width - idealIconAreaWidth produces a negative value. Math.min then selects this negative widthUntilLineNumberEnd, which causes pillRect.withWidth(negative) to create a Rect where left > right, throwing Invalid arguments: Horizontally offset by N.

Wrap the computation in Math.max(0, ...) so widthUntilLineNumberEnd is clamped to 0 when the pill is too narrow.

Fixes #301197

When pillRect.width < idealIconAreaWidth (22px) and lineNumbersWidth is 0,
the expression pillRect.width - idealIconAreaWidth produces a negative value.
Math.min then selects this negative widthUntilLineNumberEnd, which causes
pillRect.withWidth(negative) to create a Rect where left > right, throwing
'Invalid arguments: Horizontally offset by N'.

Wrap the computation in Math.max(0, ...) so widthUntilLineNumberEnd is
clamped to 0 when the pill is too narrow.

Fixes #301197
Copilot AI review requested due to automatic review settings March 15, 2026 21:58
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 the inline edits gutter indicator layout logic by preventing a negative width from being passed to Rect.withWidth(...) when the pill is narrower than the ideal icon area and line numbers are disabled (width 0).

Changes:

  • Clamp widthUntilLineNumberEnd to >= 0 when layout.lineNumbersWidth === 0 to avoid constructing invalid Rect instances.

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.

[Unhandled Error] Invalid arguments: Horizontally/Vertically offset by 4

2 participants