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

Paste still broken (2.0.0-beta.120) #2003

Closed
1 of 2 tasks
nokola opened this issue Oct 8, 2021 · 4 comments
Closed
1 of 2 tasks

Paste still broken (2.0.0-beta.120) #2003

nokola opened this issue Oct 8, 2021 · 4 comments
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@nokola
Copy link
Contributor

nokola commented Oct 8, 2021

What’s the bug you are facing?

Pasting things like **bold** or *italic* multiple times doesn't work anymore.

How can we reproduce the bug on our side?

See updated https://codesandbox.io/s/tiptap-after-paste-bug-jjoxc and bug #2002 that still reproduces.

Broken paste in above codesandbox (click to play gif):
paste_broken2

And in my project. Note: In my project I have a bit different settings than bold/italic from StarterKit, however used to work before. Not there's data loss, same as bug #2002 (click to play gif)
paste_broken3

Can you provide a CodeSandbox?

https://codesandbox.io/s/tiptap-after-paste-bug-jjoxc

What did you expect to happen?

Paste to work without extra characters or losing data.

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. 💖
@nokola nokola added the Type: Bug The issue or pullrequest is related to a bug label Oct 8, 2021
@philippkuehn
Copy link
Contributor

philippkuehn commented Oct 9, 2021

Ah, sorry for these issues. We definitely need to add some tests for these paste rules.

I know what is happening in the first gif. Because it’s already italic from the first paste, italic can’t applied a second time. But that is something I can fix. But note that the second bold is italic too because you pasted at the open end of italic.

The second gif shows a different issue. I would really like to know the config of your pasteRules because there seems to be a data loss. Can you share some code or provide a codesandbox with that config?

@nokola
Copy link
Contributor Author

nokola commented Oct 9, 2021

No problem! Here's a small repro project for the data loss: https://codesandbox.io/s/tiptap-after-paste-bug2-dataloss-dqq63?file=/src/App.vue

The changes: I added a "quickbold" extension to make bold work with just a single star e.g. *bold* Disabled the existing bold/italic in startupkit.

const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm;
// export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm;
export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm
export const QuickBold = Bold.extend({
    addInputRules() {
        return [markInputRule({ find: starInputRegex, type: this.type })];
    },

    addPasteRules() {
        return [markPasteRule({ find: starPasteRegex, type: this.type })];
    },
});

To reproduce:

  1. Open https://codesandbox.io/s/tiptap-after-paste-bug2-dataloss-dqq63?file=/src/App.vue
  2. Paste this once and press enter after pasting:
**bold**
*italic*

Expected:
*bold*
italic

Actual:
bold
*talic*
image

The "i" is lost after pressing Enter.

@nokola
Copy link
Contributor Author

nokola commented Oct 9, 2021

I know what is happening in the first gif. Because it’s already italic from the first paste, italic can’t applied a second time. But that is something I can fix. But note that the second bold is italic too because you pasted at the open end of italic.

Good insight! :)

@philippkuehn
Copy link
Contributor

found the issue. there is no issue with paste rules but with some input rule regex. input rule regex should not have the gm modifiers. paste rules regex should only have a g modifier. (see: 65eddf0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

2 participants