forked from udecode/plate
-
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.
Delete forward on empty line before code block unwraps code line udec…
- Loading branch information
1 parent
81f860f
commit c2cd206
Showing
2 changed files
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { PlateEditor, Value, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '@udecode/plate-common'; | ||
import { Editor, Path, move, removeNodes } from 'slate'; | ||
|
||
|
||
|
||
|
||
export const withParagraph = < | ||
V extends Value = Value, | ||
E extends PlateEditor<V> = PlateEditor<V> | ||
>( | ||
editor: E | ||
) => { | ||
const { deleteForward, deleteBackward } = editor; | ||
editor.deleteForward = (unit) => { | ||
if (isSelectionAtBlockStart(editor) && isSelectionAtBlockEnd(editor)) { | ||
const path = editor.selection?.focus.path; | ||
let previousListItemPath: Path; | ||
try { | ||
if (path != undefined) { | ||
previousListItemPath = Path.previous(path); | ||
} | ||
// Delete the current empty line and work as deleteBackward | ||
deleteBackward(unit); | ||
move(editor as any, { unit: "line", reverse: false }); | ||
} catch { | ||
removeNodes(editor as any); | ||
} | ||
} else { | ||
// Perform the default deleteForward behavior | ||
deleteForward(unit); | ||
} | ||
}; | ||
return editor; | ||
}; |