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]: incorrect cursor positioning when using nodePasteRule for a custom extension #5175

Open
1 task done
skassam21 opened this issue May 21, 2024 · 0 comments
Open
1 task done
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@skassam21
Copy link

Affected Packages

react

Version(s)

2.4.0

Bug Description

We currently have a custom tiptap extension that acts very similar to a Mention. We have the following paste rules:

addPasteRules() {
    return [
      nodePasteRule({
        find: createRegexFromOptions(this.options.suggestionOptions),
        type: this.type,
        getAttributes: (match) => {
          const key = match[1];
          return {
            id: key,
            label: key,
          };
        },
      }),
    ];
  },

For context, createRegexFromOptions looks like this:

function createRegexFromOptions(options: string[]) {
  const regexPattern = `\\{(${options.join("|")})\\}`;
  return new RegExp(regexPattern, "g");
}

This will look for specific tags like {Name} and convert into this custom node. When we paste text into the tiptap editor with examples of this, everything works fine, except that the cursor always ends up at the end of the last found custom node, as opposed to the end of the pasted content.

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

We'd expect the text to appear at the end of the pasted content, as opposed to at the end of the last found custom node.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.
@skassam21 skassam21 added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels May 21, 2024
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. Type: Bug The issue or pullrequest is related to a bug
Projects
Status: Triage open
Development

No branches or pull requests

1 participant