-
-
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): implement deleteCurrentNode command & fix node joining on Delete key #3192
Merged
bdbch
merged 8 commits into
main
from
2924-pressing-delete-on-an-empty-paragraph-clears-the-node-afterwards
Nov 25, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4528d32
fix(core): :bug: fix delete on empty nodes joining next node incorrectly
bdbch 2ddce4d
refactor(core): :recycle: remove unnecessary return on handleDelete k…
bdbch 7b378de
Merge branch 'main' of github.com:ueberdosis/tiptap into 2924-pressin…
bdbch b6f06a2
Merge branch 'main' of github.com:ueberdosis/tiptap into 2924-pressin…
bdbch 50d8e1f
Merge branch 'main' of github.com:ueberdosis/tiptap into 2924-pressin…
bdbch ada18e4
Merge github.com:ueberdosis/tiptap into 2923-pressing-delete-on-an-em…
bdbch c01ae55
erge branch '2924-pressing-delete-on-an-empty-paragraph-clears-the-no…
bdbch 4efbfef
Merge branch 'main' of github.com:ueberdosis/tiptap into 2924-pressin…
bdbch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { RawCommands } from '../types' | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
deleteCurrentNode: { | ||
/** | ||
* Delete the node that currently has the selection anchor. | ||
*/ | ||
deleteCurrentNode: () => ReturnType, | ||
} | ||
} | ||
} | ||
|
||
export const deleteCurrentNode: RawCommands['deleteCurrentNode'] = () => ({ tr, dispatch }) => { | ||
const { selection } = tr | ||
const currentNode = selection.$anchor.node() | ||
|
||
// if there is content inside the current node, break out of this command | ||
if (currentNode.content.size > 0) { | ||
return false | ||
} | ||
|
||
const $pos = tr.selection.$anchor | ||
|
||
for (let depth = $pos.depth; depth > 0; depth -= 1) { | ||
const node = $pos.node(depth) | ||
|
||
if (node.type === currentNode.type) { | ||
if (dispatch) { | ||
const from = $pos.before(depth) | ||
const to = $pos.after(depth) | ||
|
||
tr.delete(from, to).scrollIntoView() | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 command should be marked
@internal
or at least have its behavior documented more clearly. I tried using it thinking it would delete the current node, but the current node was not empty, so it wasn't deleted, leading me to think Tiptap was broken.