-
-
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
90b2079
commit 426e696
Showing
7 changed files
with
65 additions
and
97 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
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 |
---|---|---|
@@ -1,77 +1,49 @@ | ||
import { | ||
deleteForward, | ||
getNodeEntries, | ||
getPointBefore, | ||
isBlockAboveEmpty, | ||
isSelectionExpanded, | ||
PlateEditor, | ||
queryNode, | ||
removeNodes, | ||
Value, | ||
WithPlatePlugin, | ||
} from '@udecode/plate-common'; | ||
|
||
import { DeletePlugin } from './createDeletePlugin'; | ||
import Slate from 'slate'; | ||
|
||
/** | ||
* Set a list of element types to select on backspace | ||
*/ | ||
export const withDelete = < | ||
V extends Value = Value, | ||
E extends PlateEditor<V> = PlateEditor<V>, | ||
>( | ||
editor: E, | ||
{ | ||
options: { query }, | ||
}: WithPlatePlugin<DeletePlugin, V, E> | ||
) => { | ||
const { deleteForward } = editor; | ||
editor.deleteForward = (unit: 'character' | 'word' | 'line' | 'block') => { | ||
const { selection } = editor; | ||
console.log("outer" ,query); | ||
if(!editor.selection) return; | ||
|
||
getAboveNode, | ||
isBlockAboveEmpty, | ||
isSelectionExpanded, | ||
PlateEditor, | ||
queryNode, | ||
removeNodes, | ||
Value, | ||
WithPlatePlugin, | ||
} from '@udecode/plate-common'; | ||
|
||
import { DeletePlugin } from './createDeletePlugin'; | ||
|
||
/** | ||
* Set a list of element types to select on backspace | ||
*/ | ||
export const withDelete = < | ||
V extends Value = Value, | ||
E extends PlateEditor<V> = PlateEditor<V>, | ||
>( | ||
editor: E, | ||
{ options: { query } }: WithPlatePlugin<DeletePlugin, V, E> | ||
) => { | ||
const { deleteForward } = editor; | ||
editor.deleteForward = (unit: 'character' | 'word' | 'line' | 'block') => { | ||
if (!editor.selection) return; | ||
if (!isSelectionExpanded(editor) && isBlockAboveEmpty(editor)) { | ||
console.log("asdas"); | ||
// check when line is empty | ||
const isValidNode = queryNode(getAboveNode(editor), query); | ||
if (query) { | ||
//if query value is passed | ||
const pointBefore = getPointBefore(editor, selection as Slate.Location, { | ||
unit, | ||
}); | ||
|
||
if (pointBefore) { | ||
const [prevCell] = getNodeEntries(editor, { | ||
match: (node) => queryNode([node, pointBefore.path], query), | ||
at: pointBefore, | ||
}); | ||
if (!!prevCell && pointBefore) { | ||
console.log("valid cell"); | ||
removeNodes(editor as any); | ||
|
||
} | ||
else { | ||
console.log("invalid cell"); | ||
|
||
deleteForward(unit); | ||
} | ||
} | ||
else{ | ||
deleteForward(unit); | ||
} | ||
} | ||
else{ | ||
console.log("outside query"); | ||
//is query is passed | ||
if (isValidNode) { | ||
// cursor is in query blocks | ||
removeNodes(editor as any); | ||
} else { | ||
//fallback to default behaiour | ||
deleteForward(unit); | ||
} | ||
} else { | ||
// query is not passed, then plugin is active everywhere | ||
removeNodes(editor as any); | ||
} | ||
} else { | ||
// when line is not empty, fall back to default behavior | ||
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