-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(core): check if pos is valid before resolving in backspace core keymap handler #4835
Conversation
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
LGTM - @svenadlung any thoughts on this?
very much waiting for this. same exact problem. thanks! |
@svenadlung gentle bump |
Please describe your changes
So I'm working on a TipTap editor where I don't want to allow block elements in the document. Not exactly a common use case I'm guessing, but it makes sense for what I'm doing.
I discovered that when I override the
content
of theDocument
extension to only allow text like so......it causes an error to be thrown whenever I press
Backspace
and either:The error comes from the backspace keyboard shortcut handler which is added in TipTap core. This handler attempts to resolve a position in the document at
pos - 1
wherepos
is equal toeditor.state.selection.$anchor.pos
. I think this works fine when there are block elements in the editor since even an empty editor will still have at least an empty block element. Whenever only text is allowed, though, thispos
is equal to zero whenever the editor is empty. This results in the handler attempting to resolve the position in the document at apos
of-1
, which throws an error.How did you accomplish your changes
Added a check that
pos > 0
before attempting to resolvepos - 1
in the document.How have you tested your changes
Tested both cases where I found the error manually, and with this check, the error no longer occurs.
I also tested backspace in a more typical editor configuration with the default
Document
extension. Everything works as expected, including backspace when there is a lot of text, backspace when there is no text, and backspace when all text is selected.How can we verify your changes
To reproduce bug:
Document
as I've outlined above.Backspace
when the editor is emptyTo verify fix, repeat the process with my changes applied and see the error is gone.
Remarks
Loving TipTap so far :)
Checklist
Related issues
N/A