Skip to content

refactor(core)!: ask leaf for the heading under the caret instead of parsing the body again - #5

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-heading-at-offset
Oct 21, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-heading-at-offset

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

DocumentSession::heading_at_caret now delegates to leaf's Doc::heading_at_caret and no longer parses the body through twig a second time. leaf builds its node tree lazily, so heading_at_caret, locator_at_caret and reference_here now take the session by &mut. provui-tui's Nav::reference_here and show_reference follow.

Why

This is provui's half of leaf's task heading-at-offset. The leaf half (Doc::heading_at / heading_at_caret) has landed, and provui's lock (712f12e) already carries it. The task is done when provui's second parse is gone. twig is already out of provui-core's manifest.

Behavioural change

A heading's text is now leaf's: the words with the inline markup stripped. ## The *hard* part reads as The hard part, not The *hard* part. A same-document link from reference_here gets that label too. The #locator slug is the same as before.

Closing the task

The task file lives in leaf, so this PR can't mark it done. Once this PR merges, the task can be shelved in leaf (org shelve) with this PR's merge commit named.

Verification

  • Test first: the_heading_above_the_caret_is_what_a_locator_names now asserts the sub-heading's text and span. It failed on main ("The *hard* part" vs "The hard part") and passes with the change.
  • ship ci: all 6 jobs pass (fmt, clippy -D warnings, tests, docs, package isolation, MSRV).

…parsing the body again

`DocumentSession::heading_at_caret` parsed the body through twig a second
time because leaf had no way to answer the question. leaf now has
`Doc::heading_at_caret`, and provui's lock already carries it, so the
session asks the tree leaf holds for the body.

leaf builds that tree lazily, so the question needs `&mut`.

BREAKING CHANGE: `DocumentSession::heading_at_caret` and `locator_at_caret` take `&mut self`, and `reference_here` takes `&mut DocumentSession`.
Behavioural-change: A heading's `text` is its words with the inline markup stripped, as leaf gives them: `## The *hard* part` reads as `The hard part`, and a same-document link from `reference_here` is labelled that way. The locator slug is unchanged.
@adammharris
adammharris merged commit e25e5c7 into main Oct 21, 2026
7 checks passed
@adammharris
adammharris deleted the agent/backlog-heading-at-offset branch October 30, 2026 01:26
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.

1 participant