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 List issues & add support for Mod keys #4210

Merged
merged 4 commits into from
Aug 3, 2023
Merged

Fix List issues & add support for Mod keys #4210

merged 4 commits into from
Aug 3, 2023

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Jul 13, 2023

Please describe your changes

This PR fixes various issues with lists (for example when the cursor is placed right behind a list and backspace is pressed).

It also moves all list helpers into core so they can be used by taskLists too.

Checklist

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

Related Issues

closes #3128
closes #2747

@bdbch bdbch requested a review from svenadlung as a code owner July 13, 2023 13:40
@bdbch bdbch self-assigned this Jul 13, 2023
@netlify
Copy link

netlify bot commented Jul 13, 2023

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 2a11d39
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/64affebc3a13d0000896d17e
😎 Deploy Preview https://deploy-preview-4210--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.

@terlan4
Copy link

terlan4 commented Jul 16, 2023

When will this version be released? I would love to see my backspace work asap 🙂❤

@bdbch
Copy link
Contributor Author

bdbch commented Jul 27, 2023

@svenadlung could you take a look?

@bdbch bdbch merged commit d1e879d into develop Aug 3, 2023
15 checks passed
@bdbch bdbch deleted the list-update branch August 3, 2023 08:19
@Nantris
Copy link
Contributor

Nantris commented Aug 9, 2023

I was looking through these changes and I'm curious what the changes to the cut command accomplished? I'm curious because we're reliant on that command in our own code. Was there some mapping-related issue with the old implementation?

@bdbch
Copy link
Contributor Author

bdbch commented Aug 9, 2023

If I remember correctly the issue occured when something was cut and moved after the cut content. Since the mapping wasn't respected beforehand, the insert position was invalid.

I could check again if I find some time what it was about exactly.

@Nantris
Copy link
Contributor

Nantris commented Aug 9, 2023

I also noticed the logic in these Backspace handler lines lacks corresponding logic in the Delete handler:

if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
const { $anchor } = editor.state.selection
const $listPos = editor.state.doc.resolve($anchor.before() - 1)
const listDescendants: Array<{ node: Node, pos: number }> = []
$listPos.node().descendants((node, pos) => {
if (node.type.name === name) {
listDescendants.push({ node, pos })
}
})
const lastItem = listDescendants.at(-1)
if (!lastItem) {
return false
}
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run()
}

@Nantris
Copy link
Contributor

Nantris commented Aug 9, 2023

If I remember correctly the issue occured when something was cut and moved after the cut content. Since the mapping wasn't respected beforehand, the insert position was invalid.

Thanks for the reply @bdbch! I was curious looking at it because it seems similar to the weird mapping misbehavior in #4283

Edit: Seems pretty likely to me actually since all the mapping issues I hit were related to chained commands on lists specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants