Skip to content

Commenting on a heading reports the previous heading's text as the label #26

Description

@kenxle

Version: 0.6.0 (fa8fa41) · File: src/sdk.js, targetFor()

What happens

Select a heading in a reviewed document and the comment panel labels it with the text of the heading before it. The element index is correct; only the text is wrong. In a document whose h2s run 1. Where this came from … 5. The filter that matters most, clicking the fifth heading shows 4. Where we actually are,… · h2 5 — right element, right number, wrong name.

Not cosmetic: for kind: "element" comments the label is also sent to the agent as the comment's quote, so the agent receives a comment pointing at the wrong section and can act on the wrong part of the document.

Steps to reproduce

  1. Review a file with two same-level headings (## First section, then ## Second section, each with a line of text).
  2. Click the Second section heading to comment on it.
  3. The label reads First section · h2 2.

Cause

targetFor() builds every block's pinned label from precedingHeading(block), which walks previousElementSibling looking for an h1–h6. That's correct for a paragraph or table sitting under a heading, which is the case it was written for. When the block is itself a heading, the nearest preceding heading is the previous section's.

Suggested fix

if (!pinnedLabels.has(block)) {

  • const heading = precedingHeading(block);
    const tag = block.tagName.toLowerCase();
  • // A heading names itself. Labeling it with the heading before it reads as
  • // pointing at the previous section, which is the wrong target entirely.
  • if (/^h[1-6]$/.test(tag)) {
  •  pinnedLabels.set(block, clip(block.textContent, 40) || tag);
    
  •  return { el: block, label: pinnedLabels.get(block), authored: false };
    
  • }
  • const heading = precedingHeading(block);

The ordinal suffix isn't needed in this branch — it exists to stop same-tag siblings collapsing into one edit row, and a heading's own text already distinguishes it. Non-heading blocks keep current behavior. Applied locally against fa8fa41: syntax check passes, full suite passes (90 tests, 0 failures) on Node v24.11.1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions