Skip to content

fix(core): correct range intersection when ranges share start/end lines - #13201

Open
eeshsaxena wants to merge 1 commit into
continuedev:mainfrom
eeshsaxena:fix/range-intersection-shared-lines
Open

fix(core): correct range intersection when ranges share start/end lines#13201
eeshsaxena wants to merge 1 commit into
continuedev:mainfrom
eeshsaxena:fix/range-intersection-shared-lines

Conversation

@eeshsaxena

Copy link
Copy Markdown

Description

intersection(a, b) in core/util/ranges.ts computes the wrong start/end character in the multi-line branch when the two ranges begin (or end) on the same line.

It picked the character from whichever range's line matched startLine/endLine first:

const startCharacter = startLine === a.start.line ? a.start.character : b.start.character;

When both ranges start on that shared line, this returns a's character instead of the later of the two — and symmetrically for the end. Example (both share start line 0 and end line 3):

intersection(
  { start: { line: 0, character: 5 },  end: { line: 3, character: 4 } },
  { start: { line: 0, character: 10 }, end: { line: 3, character: 2 } },
)
// before: { start: {0, 5},  end: {3, 4} }   ❌
// after:  { start: {0, 10}, end: {3, 2} }   ✔  (later start, earlier end)

The single-line branch already does this correctly (Math.max / Math.min); this makes the multi-line branch consistent.

Fix

When the two ranges share the start line, take Math.max of the start characters; when they share the end line, take Math.min of the end characters. Otherwise the previous behavior is unchanged.

Testing

Added a ranges.test.ts case for two ranges sharing both start and end lines (fails before, passes after). All existing intersection tests still pass (they use ranges on different start/end lines, so they don't touch the changed branch). Verified the logic directly against the existing test inputs plus the new case.

In the multi-line branch, intersection picked the start character from
whichever range's start line matched startLine first, and likewise for the end.
When both ranges begin (or end) on the shared line, that dropped the
comparison: it returned a's character instead of the later start / earlier end.
Compare the characters when the lines are equal.
@eeshsaxena
eeshsaxena requested a review from a team as a code owner August 29, 2026 04:34
@eeshsaxena
eeshsaxena requested review from sestinj and removed request for a team August 29, 2026 04:34
@github-actions

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

1 participant