Skip to content

feat(reanchor): locate multi-line anchors per endpoint in the region search - #347

Merged
nownabe merged 1 commit into
mainfrom
feat/311-multiline-region-search
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
feat/311-multiline-region-search

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

PR #309 (#269 Phase 1) gave single-line anchors a bounded region search.
A multi-line anchor with an unmapped endpoint still went straight to outdated,
so a comment spanning two prose paragraphs — or a multi-line suggestion — lost
its position as soon as either paragraph was edited.

What

  • lib/pr/reanchor.ts — new exported locateSpan(oldLines, newLines, lineMap, range, quote): a mapped endpoint keeps its mapping; an unmapped one
    goes through the existing locateLine using as its Stage-A needle the part of
    quote that lies on that endpoint's line (quote.split("\n")[0] for the
    start, the last element for the end — exact under ADR 0002 §3's definition of
    quote). Null unless both endpoints resolve and the located end lies
    strictly after the located start.
  • lib/pr/reanchor.ts — reanchorByRegion loses its sl !== el bail-out.
    Multi-line columns are carried through the same diff_xIndex char diff the
    single-line path uses, ec clamped to the located end line's length; the
    range is then verified with the one rule, extractTextAtRange === quote, so
    a moved span reports mapped and an edited quote reports shifted at the
    located span. The single-line branch is unchanged.
  • lib/suggest.ts — applyAcceptedSuggestion's fallback uses the same
    locateSpan instead of refusing sl !== el; mergeLine/replaceLine become
    mergeSpan/replaceLines over the located span. The Phase-1 simplify:
    comment is gone.
  • docs/adr/0004-reanchoring.md — §3 note and mermaid, §5 (the two partial-
    span bullets collapse into one per-endpoint rule), §7 (span-local merge), and
    the Deferred entry is removed.

Tie handling (the issue's open question): unchanged — a tie is outdated,
now stated explicitly in ADR 0004 §3.
The expected position centres the search
window but never ranks candidates; breaking a similarity tie by proximity would
be a guess about which of two equally plausible lines the reviewer meant, which
is the exact failure ADR 0004 removed.

Red-test evidence

tests/pr/reanchor.test.ts, describe("multi-line region search (issue #311)"):

  • locateSpan direct test: SyntaxError: Export named 'locateSpan' not found in module lib/pr/reanchor.ts.
  • "a two-paragraph comment survives an edit elsewhere in the second paragraph":
    expected {status: "mapped", range: {sl:3, sc:10, el:5, ec:13}}, received
    {status: "outdated"}.
  • "the quoted text of a multi-line anchor was edited → shifted at the located
    span": expected {status: "shifted", range: {sl:3, sc:10, el:5, ec:13}},
    received {status: "outdated"}.

tests/suggest.test.ts, describe("span-local merge for multi-line targets (issue #311)"):

  • "a two-line suggestion applies after an earlier accept changed its first
    line": expected "h\nALPHA ONE here\nbeta TWO\nt\n", received null.
  • "a multi-line deletion via the fallback removes every span line and its
    newline": expected "h\nt\n", received null.

Three guards in the new block passed before and after and pin the rules during
the change: an end line deleted with nothing in its place, endpoints that cross
over, and a similarity tie for one endpoint all stay outdated. The existing
Phase-1 guard ("a multi-line anchor with an unmapped endpoint stays outdated")
keeps its assertion but is renamed — it now holds because a one-character line
can neither contain the quote part nor reach the similarity floor, not because
multi-line anchors are refused outright.

Checks

bun run test (737 pass, 0 fail), check:lint, check:format, typecheck,
build all pass.

Closes #311

@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe added this pull request to stack #339 September 20, 2026 06:51
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from a6a14c1 to 74731e7 Compare September 20, 2026 07:37
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from 74731e7 to 03a749c Compare September 20, 2026 08:39
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from 03a749c to 1ccb5f5 Compare September 20, 2026 08:56
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from 1ccb5f5 to 1fed175 Compare September 20, 2026 08:59
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from 1fed175 to ba51b1f Compare September 20, 2026 09:02
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from ba51b1f to 55e7268 Compare September 20, 2026 09:03
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from 55e7268 to b225806 Compare September 20, 2026 09:05
Base automatically changed from fix/313-refuse-shifted-drafts to main September 20, 2026 09:09
…search

A comment spanning two paragraphs, or a multi-line suggestion, lost its position as soon as either paragraph was edited: any unmapped endpoint went straight to outdated. Each endpoint is now located independently with the same bounded, uniqueness-gated search, using the part of the quote that lies on its own line, and the span is refused unless the located end lies strictly after the located start. Ties stay outdated - ranking two equally plausible lines by proximity is the guess ADR 0004 removed. The accept path shares the same locateSpan and merges span-locally.

Closes #311
@nownabe
nownabe force-pushed the feat/311-multiline-region-search branch from b225806 to bdc5986 Compare September 20, 2026 09:09
@nownabe
nownabe merged commit f4fd457 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the feat/311-multiline-region-search branch September 20, 2026 09:11
nownabe pushed a commit that referenced this pull request Sep 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.4.0](bark-v0.3.0...bark-v0.4.0)
(2026-09-20)


### Features

* **pr:** accept .markdown and .mdx as Markdown
([#322](#322))
([e22ee68](e22ee68)),
closes [#293](#293)
* **pr:** commit fork pull requests to the fork's repository
([#342](#342))
([4e2adef](4e2adef)),
closes [#273](#273)
* **pr:** create a top-level draft Comment's Thread with it
([#323](#323))
([6e192f3](6e192f3)),
closes [#272](#272)
* **pr:** resolve out-of-diff threads via the root comment fence
([#310](#310))
([7e0ecb9](7e0ecb9)),
closes [#270](#270)
* **reanchor:** bounded region search for single-line anchors and
line-local suggestion merge
([#309](#309))
([0f735da](0f735da)),
closes [#269](#269)
* **reanchor:** locate multi-line anchors per endpoint in the region
search ([#347](#347))
([f4fd457](f4fd457)),
closes [#311](#311)
* **review:** preview the merge for shifted suggestions in the editor
([#354](#354))
([f822f41](f822f41)),
closes [#312](#312)


### Bug Fixes

* **anchor:** define anchor.quote as the source text at anchor.range
([#327](#327))
([11a935d](11a935d)),
closes [#276](#276)
* **background:** focus an existing review tab instead of opening a
second one ([#325](#325))
([58efa63](58efa63)),
closes [#277](#277)
* **pr:** compose the quote and permalink for every out-of-diff post
([#351](#351))
([f85b99b](f85b99b)),
closes [#282](#282)
* **pr:** count patch lines starting with ++ or -- in parseRightRanges
([#314](#314))
([9dfbd46](9dfbd46)),
closes [#284](#284)
* **pr:** keep the rel=next link in the ETag cache so 304 pages still
paginate ([#318](#318))
([6472de2](6472de2)),
closes [#286](#286)
* **pr:** offer Resolve only when GitHub would accept it
([#335](#335))
([b05fdcc](b05fdcc)),
closes [#274](#274)
* **pr:** park a failed resolve toggle in synced, not draft
([#320](#320))
([56e815b](56e815b)),
closes [#275](#275)
* **pr:** post drafts in the current head's coordinates
([#303](#303))
([28ef345](28ef345))
* **pr:** recover comments stuck in syncing instead of re-posting them
([#305](#305))
([3548086](3548086))
* **pr:** refuse commits to a merged or closed PR
([#330](#330))
([2a239ff](2a239ff)),
closes [#288](#288)
* **pr:** refuse to submit a draft whose quoted text changed upstream
([#346](#346))
([d4118a4](d4118a4)),
closes [#313](#313)
* **pr:** route replies on the parent's GitHub object kind
([#326](#326))
([1df6462](1df6462)),
closes [#285](#285)
* **pr:** serialise refresh and execution under one Repository lock
([#336](#336))
([1864488](1864488)),
closes [#281](#281)
* **pr:** sweep entities left syncing at the end of a submit
([#331](#331))
([108caa9](108caa9)),
closes [#271](#271)
* **release:** pin publish-browser-extension to ^4.0.5
([#263](#263))
([b77104f](b77104f))
* **review:** derive a suggestion draft's cid from the hunk it
materialises ([#337](#337))
([963339d](963339d)),
closes [#308](#308)
* **review:** end a whole-line selection on the line it actually covers
([#319](#319))
([3364d18](3364d18)),
closes [#291](#291)
* **review:** map comment positions between head and edited coordinates
([#348](#348))
([9465718](9465718)),
closes [#283](#283)
* **review:** reject a suggestion by resolving its thread on GitHub
([#340](#340))
([d088a8d](d088a8d)),
closes [#287](#287)
* **review:** resolve accepted-suggestion threads only after the commit
lands ([#341](#341))
([770f901](770f901)),
closes [#278](#278)
* **review:** surface failed comment posts and keep the reviewer's edits
([#307](#307))
([48cb675](48cb675))
* **review:** validate the PR number from the review URL
([#321](#321))
([457a942](457a942)),
closes [#295](#295)
* **storage:** bound chrome.storage.local growth and stop quota errors
losing drafts ([#332](#332))
([1f96120](1f96120)),
closes [#289](#289)
* **suggest:** consume a longer closing fence instead of leaking a
backtick ([#316](#316))
([d2e0683](d2e0683)),
closes [#290](#290)


### Performance Improvements

* **reanchor:** replace the LCS table with a memoised line-level Myers
diff ([#344](#344))
([8caebdd](8caebdd)),
closes [#280](#280)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please-nownabe-bark[bot] <295690643+release-please-nownabe-bark[bot]@users.noreply.github.com>
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.

[Medium] Region search for multi-line anchors (per-endpoint) — #269 Phase 2

1 participant