-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fix(extension-table):Clipboard Issue: Unwanted Text Included When Pas… #5372
base: develop
Are you sure you want to change the base?
Conversation
…ting Table Columns Outside of the Editor (ueberdosis#5086)
|
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
interface _Fragment extends Fragment { | ||
content: Node[]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be extending prosemirror types. If it says it does not have a content property then it probably is not meant to be accessed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be extending prosemirror types. If it says it does not have a content property then it probably is not meant to be accessed
However, there is indeed a content property, and the type of this object is _Fragment, with its parent being _Slice. I couldn't find where they originated from; neither tipTap nor ProseMirror defines them. So I added _Fragment myself. Do you have any good solutions to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content is not meant to exposed though because it is an internal property in prosemirror: https://github.com/ProseMirror/prosemirror-model/blob/cde085e345b6815c54af9c386feb73bce3ad41ee/src/fragment.ts#L17-L18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a forEach method which allows iterating over each item: https://github.com/ProseMirror/prosemirror-model/blob/cde085e345b6815c54af9c386feb73bce3ad41ee/src/fragment.ts#L168
But I'm not sure about this approach in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a forEach method which allows iterating over each item: https://github.com/ProseMirror/prosemirror-model/blob/cde085e345b6815c54af9c386feb73bce3ad41ee/src/fragment.ts#L168
But I'm not sure about this approach in general
Thank you for your suggestion. I'll give it a try later.
if (isCellSelection(view.state.selection)) { | ||
const contentArray = (content.content as _Fragment).content | ||
let result = '' | ||
|
||
contentArray.forEach((tableRow:Node) => { | ||
const cellArr = (tableRow.content as _Fragment).content | ||
|
||
cellArr.forEach((cell:Node, cellIndex:Number) => { | ||
result = `${result} ${cell.textContent} ${Number(cellIndex) === cellArr.length - 1 ? '\n' : ''}` | ||
}) | ||
}) | ||
return result | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like the correct place for this, for example, where is the logic for adding these new lines for things like list items that you'd expect a newline between too?
Maybe they need custom renderText methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list items
I didn't take into account the situation where the table contains list items. I will reconsider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only when it contains list items, but any content that can be broken into lines.
I think that you need a custom renderText method for table rows that allow you to insert line breaks or something.
But I don't completely understand what the expected outcome should be here, a table is fundamentally very different from plain text so it would never fully be understood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix(extension-table):Clipboard Issue: Unwanted Text Included When Pasting Table Columns Outside of the Editor (#5086)
Changes Overview
Modify the clipboardTextSerializer.ts file to ensure that the clipboardText is correct after copying a cell.
Implementation Approach
Testing Done
Copy a cell from the table and paste it outside of the
Verification Steps
Additional Notes
Checklist
Related Issues
#5086