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

fix issue with code pasting from VS Code when at the last line of code #5106

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Apr 30, 2024

Please describe your changes

This PR fixes an minor issue where code copied from VSCode wouldn't be correctly pasted at the end of a document because replaceSelectionWith would cause a buggy insertion when the end position of the selection is in a node at the end of the document.

How did you accomplish your changes

I'm checking if the cursor is at the end - if so I insert the code block before the current position - otherwise I use the replaceSelectionWith function

How have you tested your changes

Tested it locally in the default demo

How can we verify your changes

See above

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

@bdbch bdbch requested a review from svenadlung as a code owner April 30, 2024 14:20
Copy link

netlify bot commented Apr 30, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit d426463
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/6630fe34c82f2300089f37df
😎 Deploy Preview https://deploy-preview-5106--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

// if the cursor is at the absolute end of the document, insert the code block before the cursor instead
// of replacing the selection as the replaceSelectionWith function will cause the insertion to
// happen at the previous node
if (view.state.selection.from === view.state.doc.nodeSize - (1 + (view.state.selection.$to.depth * 2))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to pretend that I completely understand this. What is tripping me up is the * 2.

But otherwise this looks right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 is the offset of a prosemirror node to the next one. If you for example have a nested node - the wrapping node will always add an offset of 1 at the beginning and the end which you have to account for if you want to find the correct position after said node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants