Skip to content

id(web): Tab/Shift-Tab with a selection spanning multiple blocks corrupts a paragraph and skips later code blocks #1399

Closed

Description

@dezren39

id(web): Tab/Shift-Tab with a selection spanning multiple blocks corrupts a paragraph and skips later code blocks

Summary

indentCommand / dedentCommand in pkgs/id/web/src/indent.ts assume the
selection lives inside a single code_block. When a selection starts in a
code block and extends across other blocks (select-all is the easy trigger),
the commands treat the whole span as one block's text:

  • code blocks after the first are never indented/dedented, and
  • the line-start math (computed over doc.textBetween(blockStart, blockEnd),
    whose block separators do not exist as document positions) lands inside a
    neighbouring paragraph and inserts spaces into it — corrupting non-code
    content with a formatting keystroke.

Evidence (verified this run, main 452d69e)

Targeted vitest probes against the real commands + richSchema (probe files
preserved in the fleet's run records; run with bunx vitest run in
pkgs/id/web):

  1. Doc = code_block(x\ny) + paragraph(mid) + code_block(p\nq), select
    all, Tab →
    • code_block 1 becomes x\n y (correct),
    • paragraph becomes mid — two spaces appended to the paragraph text,
    • code_block 2 stays p\nq — never indented.
  2. Doc = code_block(one) + paragraph(keep me) + code_block(two), select
    all, Tab → only the first block is indented; two is untouched.
  3. Controls behave: a selection entirely inside one code block works
    (existing indent.test.ts suite), and a selection entirely inside a
    paragraph returns false (the inCode gate at indent.ts:42-46 only
    inspects $from's parent).

Root cause

  • indent.ts:63-65 (indent) and indent.ts:100-102 (dedent): blockStart
    comes from $from.start($from.depth) and blockEnd from
    $to.end($to.depth) — two different nodes when the selection spans blocks —
    and textBetween(blockStart, blockEnd) is then scanned for \n as if it
    were a single code block's text. Positions derived from that joined string
    do not correspond to document positions once block boundaries (and
    textBetween's separators) intervene.
  • The inCode check (indent.ts:42-49, 93-97) only examines the selection's
    head parent, so a spanning selection is accepted and processed with the
    single-block math. This is the multi-block sibling of id(web): Tab/Shift-Tab on a selection indents/dedents the wrong lines — unselected lines changed, selection's first line skipped #714 (which fixed
    wrong-line selection within one block; its tests still only build
    single-code-block documents).

Why it matters

Tab is a formatting key users hit with large selections reflexively
(select-all + Tab to reindent a file is a standard gesture). Today that
gesture silently edits prose paragraphs and leaves later code blocks
unindented — a data-corruption papercut in the editor's most basic
indentation path.

Acceptance criteria

  • Tab with a selection spanning multiple blocks indents the selected
    lines of every code_block the selection overlaps, and modifies no
    non-code content (paragraph text byte-identical).
  • Shift-Tab under the same conditions dedents every overlapped
    code_block's selected lines, with the same no-prose-edits guarantee.
  • Single-block behaviour is unchanged: the existing indent.test.ts
    suite (including the id(web): Tab/Shift-Tab on a selection indents/dedents the wrong lines — unselected lines changed, selection's first line skipped #714 cases) passes unmodified.
  • New tests cover multi-block selections (code+paragraph, and
    code+paragraph+code) for both commands, including select-all.

Activity

  1. developing-today commented on Oct 27, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 27, 2026
  3. dezren39 commented on Oct 27, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: new-issue-creator-code-b run 2026-10-27 06:00 CDT
    • Found via: filed this run
    • Task: Triage the multi-block Tab/Shift-Tab defect: indent/dedent commands assume a single-code_block selection; spanning selections corrupt a neighbouring paragraph and skip later code blocks.
    • Expectation: effort/s — done when every overlapped code_block's selected lines are indented/dedented, non-code content is untouched, and multi-block regression tests exist.
    • Links: evidence probes preserved in the fleet run records (probe-2026-10-27-0605-b); related id(web): Tab/Shift-Tab on a selection indents/dedents the wrong lines — unselected lines changed, selection's first line skipped #714 (intra-block sibling, closed).
  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 28, 2026
  5. 57 remaining items

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Oct 31, 2026
  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  8. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 31, 2026
  9. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: queue worker (repo-worker-code), Lane A shift
    • Session / ID: queue task 1682 (repo-health-code-pilot), completed 2026-10-31T03:12Z
    • Found via: queue claim (park resume)
    • Task: PR fix(id/web): per-block indent/dedent for multi-block selections (#1399) #2872 merged (squash, 9813b78). This shift first fixed the PR-caused web-fmt (indent.ts) and web-lint (indent.test.ts:79) failures from run 41159703171 and pushed 8bfaaf5; Codex re-review on that head completed with no findings. The re-dispatched id-check run 41161434480 sat queued 25+ minutes with zero jobs started (runner congestion), so the web legs were verified locally with the identical toolchain CI runs: biome format + lint clean on both touched files, tsc --noEmit exit 0, indent tests 31/31, full web suite 485 passed / 1 failed — the one failure is search-panel.test.ts's aria-label expectation ("Replace all" vs "Replace all matches"), in files this PR does not touch and byte-identical to main: pre-existing. This issue auto-closed by the merge.
    • Expectation: done — task 1682 completed as fixed_merged; in-flight labels removed.
    • Links: PR fix(id/web): per-block indent/dedent for multi-block selections (#1399) #2872
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:in-reviewtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions