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]: Wrong link on paste with hard break #5679

Closed
1 task done
Ste35 opened this issue Sep 29, 2024 · 7 comments · Fixed by #5836 · May be fixed by bdbch/tiptap#1, DavidAlphaFox/tiptap#1 or Senobraz/tiptap#1
Closed
1 task done

[Bug]: Wrong link on paste with hard break #5679

Ste35 opened this issue Sep 29, 2024 · 7 comments · Fixed by #5836 · May be fixed by bdbch/tiptap#1, DavidAlphaFox/tiptap#1 or Senobraz/tiptap#1
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

@Ste35
Copy link

Ste35 commented Sep 29, 2024

Affected Packages

extension-link

Version(s)

2.6.6

Bug Description

Hi, I'd like to report a possibile bug that occurs when pasting a link with a new line separated by an hard break (I hope it's not a duplicate!).

When coping and pasting together:

  • a line with a link and
  • a following line separated by an hard break (that is a br)

the pasted link "extends" to the first word of the following line and the link pasted is incorrect:
tiptap-issue-1
(in this case, the pasted link will be https://google.comThis)

The problem doesn't show up if the two lines are in different paragraphs:
tiptap-issue-2

You can also see the same issue in the Tiptap public demo: https://templates.tiptap.dev/
tiptap-issue-3

Is this an actual issue or am I missing something?
Thank you for your work!

Browser Used

Chrome

Code Example URL

https://stackblitz.com/edit/react-xqt1gu?file=src%2FApp.js

Expected Behavior

The copied link and the following line should be kept as in the original source.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.
@Ste35 Ste35 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 Sep 29, 2024
@iropolo
Copy link

iropolo commented Nov 19, 2024

Same issue.
Probably related to #5335

Reproduce issue on: https://templates.tiptap.dev/cqgCzK9LLr

Video:

Screen.Recording.2024-11-19.at.16.49.00.mov

@nperez0111
Copy link
Contributor

It's likely this bit of code here which is trying to get all of the pasted content as a string to see what can be linked:

let textContent = ''
slice.content.forEach(node => {
textContent += node.textContent
})

I would be happy to accept a contribution here. I think that all that needs to be done is to append a newline to each node.textContent added, so that when we look for links, it will not try to include the next word as the link.

I just don't have time to work on this at the moment & validate it. Would appreciate your help here @iropolo & @Ste35

@iropolo
Copy link

iropolo commented Nov 25, 2024

Huh I spend some time

I take a look into these files

->

addPasteRules() {
return [
markPasteRule({
find: text => {

->

export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }): Plugin[] {

->

return new PasteRule({
find: config.find,
handler: ({
state, range, match, pasteEvent,
}) => {

Somewhere in markPasteRule seems like is messing with the nodes.


Process:

  1. PasteRule
  2. MarkPasteRule
  3. PasteRule

At the beginning, the node looks like: (in pasteRule)

Screenshot 2024-11-25 at 11 18 35 2 nodes. Second node with 2 content, link+text, separated.

Then, it starts the process of:

state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.isTextblock || node.type.spec.code) {
return

This will be run twice, 1 for each node:

These are the console.logs of text param:

addPasteRules() {
return [
markPasteRule({
find: text => {

First return:

image

-> form:

Second return:

image

-> https://google.comMake

Finally the second node content seems to be unifed:
Result:

Screenshot 2024-11-25 at 11 21 46

2 nodes.
Second node with 1 content unified.


I managed to ->

append a newline to each node.textContent added

I update

let textContent = ''
slice.content.forEach(node => {
textContent += node.textContent
})

To include a newline and this is the result (console.log of textContent value):

Before:
image

After:
image

Seems to looks ok in console.log() but the final result get transformed... seems the process go further.

Sorry if I get confused with the process or misunderstand it.
cc. @nperez0111

@alexvcasillas
Copy link
Contributor

Hey @Ste35 we have identified the root cause of this issue and will be fixed with the next release of the extension-link package :)

@GiuseppeFantoni
Copy link

GiuseppeFantoni commented Dec 3, 2024

@alexvcasillas @nperez0111

I believe this problem has not been resolved

eu.-.Chat.-.Google.Chrome.2024-12-02.22-43-36.mp4

@alexvcasillas
Copy link
Contributor

alexvcasillas commented Dec 3, 2024

@alexvcasillas @nperez0111

I believe this problem has not been resolved

eu.-.Chat.-.Google.Chrome.2024-12-02.22-43-36.mp4

Hey @GiuseppeFantoni we haven't released the fix yet, we will do it soon as we're gathering more fixes so we batch some of them :)

We have upstreamed this to Linkify and they will fix it on their end so in the meantime we will have the fix applied on our end

@giuseppeagostini-hotmart

@alexvcasillas Hi, Good morning, do we have any expectation of when this issue will be fixed?

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
None yet
6 participants