Skip to content

Update correct tag tree jump progressions when splitting outer group - #8778

Merged
laurmaedje merged 1 commit into
mainfrom
fix-nested-links
Aug 26, 2026
Merged

laurmaedje merged 1 commit into
mainfrom
fix-nested-links

Conversation

@saecki

@saecki saecki commented Aug 25, 2026

Copy link
Copy Markdown
Member

The issue was that this would look up the previous ID of the jump progression in the list, intstead of just using the ID of the stack entry. That jump progression in the list could have already been updated by a previous splitting of groups. Thus jump progressions of a nested group were updated instead of the one that we actually care about.

Here is an illustration of what happens with the two nested links in the added test.

= 1. Initial break
After encountering the following tags:

start par-1
    start link-1
        start link-2
end par-1

We have the following intermediate tree:

- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak) <- here

= 2. New paragraph
Now we find the start tag of the second paragraph:

start par-2

It's naively inserted into the current tree

- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
        - par-2 <- here

= 3. Break of inner link group (link-2)
Now we find the end tag of the inner link:

end link-2

The paragraph is moved out of the inner link, and a new link is added to it instead. This somewhat transposes the nesting order, but in the end it will all make sense. Because the newly added link was just closed, we're still inside the paragraph group.

- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
    - par-2 <- here
        - link-2 (weak)

While doing this tree transformation we update the previous jump progressions that jumped into the par-2 of the previous tree structure, to jump into the newly added link-2 instead. Thus updating the group id in the progression list, but not the group id of the stack entry, that's still active.

= 4. Break of outer link group (link-1)
Now we find the end tag of the outer link:

end link-1

We move par-2 out of the closed outer link (link-1) with a similar transformation and add the nested link-1. All immediate children of par-2 will be moved into link-1 instead. To make the transformation complete we need to update the jump progressions that previously jumped into par-2 to jump into the newly added link-1 instead.

- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
- par-2 <- here
    - link-1 (weak)
        - link-2 (weak)

This is were the bug came into place. The indirect lookup of the ID would resolve the ID of the inner link-2 instead.

let prev = tree.progressions[entry.prog_idx as usize];

The wrong progresssions were updated, and our newly added link-1 would never be visited by the progression list, because the progression still jumped into par-2.

= 5. Link ancestor
Because we never visited the last link-1 group, the link annotation couldn't find its ancestor and would generate an internal error.

@saecki
saecki force-pushed the fix-nested-links branch 2 times, most recently from 2c7f51e to e6e0871 Compare August 25, 2026 15:25
@laurmaedje laurmaedje added waiting-on-review This PR is waiting to be reviewed. accessibility Anything related to accessibility labels Aug 25, 2026
Comment thread tests/suite/pdftags/link.typ Resolved
@laurmaedje laurmaedje added waiting-on-author Pull request waits on author and removed waiting-on-review This PR is waiting to be reviewed. labels Aug 26, 2026
The issue was that this would look up the previous ID of the jump
progression in the list, intstead of just using the ID of the stack
entry. That jump progression in the list could have already been updated
by a previous splitting of groups. Thus jump progressions of a nested
group were updated instead of the one that we actually care about.

Here is an illustration of what happens with the two nested links in the
added test.

= 1. Initial break
After encountering the following tags:
```
start par-1
    start link-1
        start link-2
end par-1
```

We have the following intermediate tree:
```
- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak) <- here
```

= 2. New paragraph
Now we find the start tag of the second paragraph:
```
start par-2
```

It's naively inserted into the current tree
```
- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
        - par-2 <- here
```

= 3. Break of inner link group (link-2)
Now we find the end tag of the inner link:
```
end link-2
```

The paragraph is moved out of the inner link, and a new link is added to
it instead. This somewhat transposes the nesting order, but in the end
it will all make sense. Because the newly added link was just closed,
we're still inside the paragraph group.
```
- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
    - par-2 <- here
        - link-2 (weak)
```
While doing this tree transformation we update the previous jump
progressions that jumped into the `par-2` of the previous tree
structure, to jump into the newly added `link-2` instead.
Thus updating the group id in the progression list, but not the group id
of the stack entry, that's still active.

= 4. Break of outer link group (link-1)
Now we find the end tag of the outer link:
```
end link-1
```

We move `par-2` out of the closed outer link (`link-1`) with a similar
transformation and add the nested `link-1`. All immediate children of
`par-2` will be moved into `link-1` instead. To make the transformation
complete we need to update the jump progressions that previously jumped
into `par-2` to jump into the newly added `link-1` instead.
```
- par-1
    - link-1
        - link-2
- link-1 (weak)
    - link-2 (weak)
- par-2 <- here
    - link-1 (weak)
        - link-2 (weak)
```
This is were the bug came into place. The indirect lookup of the ID
would resolve the ID of the inner `link-2` instead.
```rs
let prev = tree.progressions[entry.prog_idx as usize];
```
The wrong progresssions were updated, and our newly added `link-1` would
never be visited by the progression list, because the progression still
jumped into `par-2`.

= 5. Link ancestor
Because we never visited the last `link-1` group, the link annotation
couldn't find its ancestor and would generate an internal error.
@laurmaedje
laurmaedje added this pull request to the merge queue Aug 26, 2026
@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Aug 26, 2026
Merged via the queue into main with commit 23ed3c3 Aug 26, 2026
17 checks passed
@saecki
saecki deleted the fix-nested-links branch August 26, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility Anything related to accessibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants