Skip to content

fix: match capture header paths regardless of statistics cookies - #1141

Open
officialasishkumar wants to merge 4 commits into
200ok-ch:masterfrom
officialasishkumar:fix/1037/capture-path-statistics-cookies
Open

officialasishkumar wants to merge 4 commits into
200ok-ch:masterfrom
officialasishkumar:fix/1037/capture-path-statistics-cookies

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #1037

As a user with capture templates, when the target header carries a statistics cookie like Tasks [2/5], I want the header path Tasks to find it, so that captures keep landing in the right place while the count changes.

Problem

headerWithPath compared every path segment with the header's raw title, cookies included. So:

  • the path Tasks never matched Tasks [2/5], and
  • a path that spelled out the cookie, Tasks [2/5], stopped matching as soon as a child changed state.

When the path didn't match, an in-app capture was dropped without a message (insertCapturePosition returns no position). A capture from a URL failed with "header path invalid".

Fix

headerWithPath first looks for a header whose title equals the path segment exactly, as before. Only if there is none does it compare the titles with all statistics cookies ([n/m], [n%], also empty ones) removed. This applies on every level of the path.

Because the exact match comes first, existing templates keep their target, even when a sibling differs only by its cookie. Org mode's own heading lookup ignores statistics cookies in the same way (org-complex-heading-regexp-format).

The README section on header paths and the changelog mention the new behaviour.

Tests

  • src/lib/org_utils.unit.test.js: cookies at the start, middle and end of a title, together with a TODO keyword and tags, a changed count, cookies on nested levels, preference for the exact title, and brackets that are not cookies.
  • e2e/tests/org-file/capture.spec.js: rename the sample's Groceries header to Groceries [0/0], capture with the Groceries template (path Capture > Groceries), and check that the new task lands below it and the cookie becomes [0/1]. The test fails on master because nothing is inserted.
  • yarn eslint, yarn prettier-eslint --list-different, yarn test (575 tests), yarn build, and the Chromium E2E suite (63 tests) all pass locally.

…ok-ch#1037)

A capture template's header path was compared against the raw title of
each header, which includes statistics cookies such as [2/5] or [40%].
The path "Tasks" therefore never matched the header "Tasks [2/5]", and a
path that spelled out the cookie stopped matching as soon as a child
changed state. In-app captures were then silently dropped, and URL
captures failed with "header path invalid".

headerWithPath now first looks for a header whose title equals the path
segment exactly, and only if there is none compares titles with all
statistics cookies removed. The exact match keeps existing templates
pointing at the same header when a sibling differs only by its cookie.
Org mode's own heading lookup ignores statistics cookies the same way
(see org-complex-heading-regexp-format).
@officialasishkumar

Copy link
Copy Markdown
Author

The red e2e jobs aren't caused by this change: they fail in the "Install Playwright Browser" step with Playwright does not support chromium on ubuntu26.04-x64 (likewise for firefox and webkit), because ubuntu-latest now resolves to Ubuntu 26.04 and the pinned Playwright 1.57 doesn't support it yet. Pinning the e2e job to ubuntu-24.04 or upgrading Playwright should fix it, and master will hit the same thing on its next run. The build job (eslint, prettier-eslint, jest, production build) and docs pass. I ran the e2e suite locally in the official Playwright 1.57 container: the whole chromium project passes, and the new tests also pass on firefox, webkit, Mobile Chrome and Mobile Safari.

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.

Capture template and statistics cookies

2 participants