Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Suggestion findSuggestionMatch method doesn't work properly #4033

Open
1 of 2 tasks
amir-armantaheri opened this issue May 10, 2023 · 1 comment
Open
1 of 2 tasks
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug

Comments

@amir-armantaheri
Copy link

Which packages did you experience the bug in?

Suggestion

What Tiptap version are you using?

2.0

What’s the bug you are facing?

when i am using suggestion for adding a custom node, i can add only one custom node in a paragraph
after add once suggestion doesn't appear again.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

i implemented a function node that has some argument nodes as content, and also i have a suggestion for adding a function to document, so my function node isn't a leaf and also isn't a text node so in textBetween function it consider as a empty text
here is textBetween function:

textBetween(from, to, blockSeparator, leafText) {
    let text = "", separated = true;
    this.nodesBetween(from, to, (node, pos) => {
        if (node.isText) {
            text += node.text.slice(Math.max(from, pos) - pos, to - pos);
            separated = !blockSeparator;
        }
        else if (node.isLeaf) {
            if (leafText) {
                text += typeof leafText === "function" ? leafText(node) : leafText;
            }
            else if (node.type.spec.leafText) {
                text += node.type.spec.leafText(node);
            }
            separated = !blockSeparator;
        }
        else if (!separated && node.isBlock) {
            text += blockSeparator;
            separated = true;
        }
    }, 0);
    return text;
}

in Suggestion you find text like this:

  const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
  const match = Array.from(text.matchAll(regexp)).pop()

because of textBetween my function node will convert as empty text, but the function node has a size bigger than zero (2 for function plus 2 for any arguments)
and the bug that i faced is here, where you find the absolute position of the match in the document:

const from = match.index + $position.start()
let to = from + match[0].length

so "from" and "to" here will be wrong because match object that generated base of textBetween, and the match.index always is a number lower than correct position of node,
i believe here we shouldn't use match object to find position.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@amir-armantaheri amir-armantaheri added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug labels May 10, 2023
@tonyhallett
Copy link

Should this be closed as issue pertaining to an old version ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug
Projects
Status: Triage open
Development

No branches or pull requests

4 participants