-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51b62e7
commit 690a3f3
Showing
7 changed files
with
79 additions
and
27 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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { createPluginFactory, QueryNodeOptions } from '@udecode/plate-common'; | ||
|
||
import { withCreateRemoveOnDeleteForward } from './withCreateRemoveOnDeleteForward'; | ||
|
||
export type RemoveOnDeleteForwardPlugin = { | ||
query?: QueryNodeOptions; | ||
removeNodeIfEmpty?: boolean; | ||
}; | ||
|
||
export const KEY_FORWARD_DELETE_BEFORE_CODE_BLOCK = 'forwardDeleteBeforeCodeBlock'; | ||
|
||
/** | ||
* @see {@link withCreateRemoveOnDeleteForward} | ||
*/ | ||
export const createRemoveOnDeleteForwardPlugin = | ||
createPluginFactory<RemoveOnDeleteForwardPlugin>({ | ||
key: KEY_FORWARD_DELETE_BEFORE_CODE_BLOCK, | ||
withOverrides: withCreateRemoveOnDeleteForward, | ||
options: { | ||
removeNodeIfEmpty: true, | ||
}, | ||
}); |
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,40 @@ | ||
import { | ||
isBlockAboveEmpty, | ||
isSelectionExpanded, | ||
PlateEditor, | ||
removeNodes, | ||
Value, | ||
WithPlatePlugin, | ||
} from '@udecode/plate-common'; | ||
|
||
import { RemoveOnDeleteForwardPlugin } from './createRemoveOnDeleteForwardPlugin'; | ||
|
||
/** | ||
* Set a list of element types to select on backspace | ||
*/ | ||
export const withCreateRemoveOnDeleteForward = < | ||
V extends Value = Value, | ||
E extends PlateEditor<V> = PlateEditor<V>, | ||
>( | ||
editor: E, | ||
{ | ||
options: { query, removeNodeIfEmpty }, | ||
}: WithPlatePlugin<RemoveOnDeleteForwardPlugin, V, E> | ||
) => { | ||
const { deleteForward } = editor; | ||
|
||
editor.deleteForward = (unit: 'character' | 'word' | 'line' | 'block') => { | ||
const { selection } = editor; | ||
if(!editor.selection) return; | ||
if (!isSelectionExpanded(editor) && isBlockAboveEmpty(editor)) { | ||
removeNodes(editor as any); | ||
} else { | ||
deleteForward(unit); | ||
} | ||
}; | ||
|
||
return editor; | ||
}; | ||
|
||
|
||
|
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