forked from ianstormtaylor/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add shouldMergeNodesRemovePrevNode (ianstormtaylor#5621)
* chore: add shouldMergeNodesRemovePrevNode * fix: typo
- Loading branch information
1 parent
39469df
commit fc8577a
Showing
5 changed files
with
37 additions
and
11 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EditorInterface, Element, Editor, Text } from '../interfaces' | ||
|
||
export const shouldMergeNodesRemovePrevNode: EditorInterface['shouldMergeNodesRemovePrevNode'] = | ||
(editor, [prevNode, prevPath], [curNode, curNodePath]) => { | ||
// If the target node that we're merging with is empty, remove it instead | ||
// of merging the two. This is a common rich text editor behavior to | ||
// prevent losing formatting when deleting entire nodes when you have a | ||
// hanging selection. | ||
// if prevNode is first child in parent,don't remove it. | ||
|
||
return ( | ||
(Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode)) || | ||
(Text.isText(prevNode) && | ||
prevNode.text === '' && | ||
prevPath[prevPath.length - 1] !== 0) | ||
) | ||
} |
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