[issues/306] Fix toInputSelection zero-width selection bug#313
Conversation
## 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)
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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)
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. Comment |
Summary
Fixes
SELECTION_ZERO_WIDTHvalidation 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
adjustedEndCharactercalculation intoInputSelection.tswhen normalizing trailing newline selectionscharacter: 0instead of line length)generateLinkFromSelections.test.tsthat verify full flow without mockingKey Discoveries
sel.end.line > sel.start.line && sel.end.character === 0(theincludesTrailingNewlinecondition)coverage = FullLine, so the fix only prevents validation failure - link output (#L5,#L5-L10) remains unchangedTest Plan
#L5(no char positions)#L5-L7(no char positions)#L5C9-L5C19(with char positions)Documentation
Related