fix: Fix a bug in replacement in deeply-nested inline nodes with content #7

Closed
massifrg wants to merge 2 commits from dev into main
massifrg commented 2024-07-15 12:24:20 +02:00 (Migrated from github.com)

It solves the bug described here, for replacements that happen in inline nodes whose content is made of non-inline nodes (e.g. a footnote that contains blocks, like Note in Pandoc model).

The patch looks for the upper node that has no inline ancestors, and it searches backwards until depth 1:

  let level = $from.depth
  for (let l = level; l > 0; l--)
    if ($from.node(l).isInline) level = l - 1

(I realize I forgot indentation on the third line in my PR, you should fix it, sorry @marijnh )

Maybe this is more efficient (but I have not tested it):

  let level = $from.depth
  for (let l = 1; l <= $from.depth; l++)
    if ($from.node(l).isInline) { level = l - 1; break }
It solves the bug described [here](https://github.com/ProseMirror/prosemirror-search/pull/6#issuecomment-2228124468), for replacements that happen in inline nodes whose content is made of non-inline nodes (e.g. a footnote that contains blocks, like `Note` in [Pandoc model](https://hackage.haskell.org/package/pandoc-types-1.23/docs/Text-Pandoc-Definition.html#t:Inline)). The patch looks for the upper node that has no inline ancestors, and it searches backwards until depth 1: ```ts let level = $from.depth for (let l = level; l > 0; l--) if ($from.node(l).isInline) level = l - 1 ``` (I realize I forgot indentation on the third line in my PR, you should fix it, sorry @marijnh ) Maybe this is more efficient (but I have not tested it): ```ts let level = $from.depth for (let l = 1; l <= $from.depth; l++) if ($from.node(l).isInline) { level = l - 1; break } ```
marijnh commented 2024-07-16 08:44:28 +02:00 (Migrated from github.com)

I went with another solution (see attached patch) instead.

I went with another solution (see attached patch) instead.
massifrg commented 2024-07-16 10:38:42 +02:00 (Migrated from github.com)

A solution with less computations, fine!

Unfortunately that kind of footnotes model is a way of multiplying computations.

Usually you have blocks of blocks, blocks of inlines and, sometimes, inlines of inlines. From roots to leaves.

The Pandoc Note model reopens the cycle, because it's an inline container of blocks, so, in theory, the cycle starts over again. From root to leaves, and then from other roots again.

In one of my documents I have even notes inside notes, and I verified this patch works.

Again, thank you!

A solution with less computations, fine! Unfortunately that kind of footnotes model is a way of multiplying computations. Usually you have blocks of blocks, blocks of inlines and, sometimes, inlines of inlines. From roots to leaves. The Pandoc `Note` model reopens the cycle, because it's an inline container of blocks, so, in theory, the cycle starts over again. From root to leaves, and then from other roots again. In one of my documents I have even notes inside notes, and I verified this patch works. Again, thank you!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-search!7
No description provided.