Repository navigation
fix(id/web): per-block indent/dedent for multi-block selections (#1399) - #2872
Conversation
Tab/Shift-Tab with a selection spanning multiple blocks corrupted a neighbouring paragraph and skipped later code blocks: line math ran on doc.textBetween across block boundaries as one block's text. Iterate every code_block intersecting the selection and do line math per block, clamped to the selection portion; non-code content is never modified. Adds code+paragraph(+code) regression tests for both commands.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 31 minutes. View limit details
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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3e29857b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Strict overlap: a selection merely touching the block's edge | ||
| // covers none of its characters, so the block is skipped. | ||
| if (contentStart >= to || contentEnd <= from) continue; | ||
| for (const lineStart of selectedLineStarts(lineStarts, Math.max(from, contentStart), Math.min(to, contentEnd))) { |
There was a problem hiding this comment.
Preserve selected trailing empty lines when clamping ranges
When a selection continues beyond a code block ending in \n, clamping its endpoint to contentEnd makes selectedLineStarts exclude the block's trailing empty line: that position is also a line start, which the helper treats as an exclusive selection boundary. For example, selecting across code_block("a\n") + code_block("b") now leaves the first block as " a\n" instead of " a\n ", regressing indentation of that selected blank line. Preserve the distinction between a selection actually ending at that line start and one continuing into another block.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Disposition (queue worker, lane D, task 1682): CONFIRMED valid — will fix, not merge past it. Root cause as described: indentCommand/dedentCommand clamp the per-block end to contentEnd (indent.ts:138), so selectedLineStarts sees an endpoint exactly on the trailing line start and applies its exclusive-boundary rule (#714), even though the real selection continues into the next block. Fix direction: distinguish a clamped end from a true selection end (e.g. pass a flag / use contentEnd+epsilon when the unclamped selection extends beyond this block) so the trailing empty line is included only when the selection actually continues past it; add a regression test for code_block("a\n") + code_block("b") cross-block selection. Blocked this shift on the laptop SSH outage (fleet rule: edits in a laptop worktree); task 1682 parked on that + this fix.
There was a problem hiding this comment.
Fixed in 9d5d262 (queue worker lane E, task 1682): selectedLineStarts gains an endInclusive flag; indent/dedent pass it when the real selection continues past the block (to > contentEnd), so a trailing empty line at the clamped end is now included only in that case. A selection genuinely ending at that line start keeps the exclusive-boundary rule. Regression tests added for both commands (code_block("a\n") + code_block("b") cross-block, plus the exact-end control case). Laptop: bun vitest indent.test.ts 31/31 pass, tsc --noEmit clean.
|
Fmt/lint fix pushed: web-fmt/biome named indent.ts (biome format applied) and web-lint flagged indent.test.ts:79 (forEach callback returning push() result — now a block body). Verified on laptop: biome lint clean on both files, vitest indent.test.ts 31/31 pass. Re-dispatching id-check for the new head. @codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
🤖 Agent note · salvage check (duplicate PR disposition)
|
Fixes #1399 (queue task 1682).
Problem
indentCommand/dedentCommandinpkgs/id/web/src/indent.tsderivedblockStartfrom$fromandblockEndfrom$to— different nodes when a selection spans blocks — and scanneddoc.textBetweenacross block boundaries as one block's text. With a selection spanningcode_block(x\ny) + paragraph(mid) + code_block(p\nq), Tab indented block 1, appended spaces to the prose (mid), and skipped block 2.Fix
Both commands now iterate every
code_blockintersecting the selection (doc.nodesBetween) and do line math per block: each block's own start/end, line starts from its own text, selection portion clamped to the block, reusingselectedLineStartsper block (including the #1038 binary-search helper, unchanged). Dedent removes up to 2 leading spaces per overlapped line using that block's own text. Edits are collected against the original doc and applied in descending position order. Non-code content is never modified; a selection overlapping no code block still returnsfalse.Single-block and single-cursor semantics are unchanged (verified by the existing 22 tests passing unmodified, including the #714 cases).
Tests
cd pkgs/id/web && bunx vitest run src/indent.test.ts— 28/28 pass (22 existing + 6 new#1399tests: code+paragraph+code and code+paragraph selections for both commands, plus no-overlap-returns-false for both).tsc --noEmit— clean.search-panel.test.ts(aria-labelReplace all matchesvsReplace all) — pre-existing on cleanmain, unrelated to this change (verified with this branch's changes stashed).Need help on this PR? Tag
@codesmith-botwith what you need.