Skip to content

[issues/306] Fix toInputSelection zero-width selection bug#313

Merged
couimet merged 1 commit intomainfrom
issues/306
Feb 6, 2026
Merged

[issues/306] Fix toInputSelection zero-width selection bug#313
couimet merged 1 commit intomainfrom
issues/306

Conversation

@couimet
Copy link
Owner

@couimet couimet commented Feb 6, 2026

Summary

Fixes SELECTION_ZERO_WIDTH validation error when using Ctrl+L or triple-click to select full lines. When VSCode reports a selection ending at the start of the next line (e.g., {line: 20, char: 0} to {line: 21, char: 0}), the normalization now correctly sets the end character to the line length instead of 0.

Changes

  • Add adjustedEndCharacter calculation in toInputSelection.ts when normalizing trailing newline selections
  • Update 4 tests that previously codified the buggy behavior (expected character: 0 instead of line length)
  • Add 3 integration tests in generateLinkFromSelections.test.ts that verify full flow without mocking

Key Discoveries

  • The bug triggers when sel.end.line > sel.start.line && sel.end.character === 0 (the includesTrailingNewline condition)
  • Affects both single-line (Ctrl+L) and multi-line (multiple Ctrl+L) selections
  • Character positions are ignored when coverage = FullLine, so the fix only prevents validation failure - link output (#L5, #L5-L10) remains unchanged
  • Issue Fix stale selection error after external file modification #260 (external file modification causing stale selections) was closed as won't-do since the logs revealed this different root cause

Test Plan

  • All 1403 tests pass
  • 4 test expectations updated to expect correct line lengths
  • 3 integration tests added to verify link format preservation:
    • Single full-line selection (Ctrl+L) → #L5 (no char positions)
    • Multi-line full selection (Ctrl+L x3) → #L5-L7 (no char positions)
    • Partial selection ending at next line → #L5C9-L5C19 (with char positions)
  • Manual testing: Open any file, Ctrl+L to select a line, generate link - should work without error

Documentation

  • CHANGELOG.md: Entry added to Fixed section
  • README.md: Not needed - internal bug fix, no user-facing API changes

Related

## Summary

Fixes `SELECTION_ZERO_WIDTH` validation error when using Ctrl+L or triple-click to select full lines. When VSCode reports a selection ending at the start of the next line (e.g., `{line: 20, char: 0}` to `{line: 21, char: 0}`), the normalization now correctly sets the end character to the line length instead of 0.

## Changes

- Add `adjustedEndCharacter` calculation in `toInputSelection.ts` when normalizing trailing newline selections
- Update 4 tests that previously codified the buggy behavior (expected `character: 0` instead of line length)
- Add 3 integration tests in `generateLinkFromSelections.test.ts` that verify full flow without mocking

## Key Discoveries

- The bug triggers when `sel.end.line > sel.start.line && sel.end.character === 0` (the `includesTrailingNewline` condition)
- Affects both single-line (Ctrl+L) and multi-line (multiple Ctrl+L) selections
- Character positions are ignored when `coverage = FullLine`, so the fix only prevents validation failure - link output (`#L5`, `#L5-L10`) remains unchanged
- Issue #260 (external file modification causing stale selections) was closed as won't-do since the logs revealed this different root cause

## Test Plan

- [x] All 1403 tests pass
- [x] 4 test expectations updated to expect correct line lengths
- [x] 3 integration tests added to verify link format preservation:
  - Single full-line selection (Ctrl+L) → `#L5` (no char positions)
  - Multi-line full selection (Ctrl+L x3) → `#L5-L7` (no char positions)
  - Partial selection ending at next line → `#L5C9-L5C19` (with char positions)
- [ ] Manual testing: Open any file, Ctrl+L to select a line, generate link - should work without error

## Documentation

- [x] CHANGELOG.md: Entry added to Fixed section
- [x] README.md: Not needed - internal bug fix, no user-facing API changes

## Related

- Closes #306
- Related to #258 (parent issue for stale selection debugging)
- Closes #260 as won't-do (original hypothesis was wrong)
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Warning

Rate limit exceeded

@couimet has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issues/306

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@couimet couimet merged commit 9639f28 into main Feb 6, 2026
2 checks passed
@couimet couimet deleted the issues/306 branch February 6, 2026 20:16
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.

Fix toInputSelection incorrectly normalizing full-line selections to zero-width Fix stale selection error after external file modification

1 participant