-
-
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.
Toggle > Handle deleteForward before a non-selectable and deleteBackw…
…ard after a non-selectable
- Loading branch information
Showing
4 changed files
with
99 additions
and
3 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
37 changes: 37 additions & 0 deletions
37
packages/toggle/src/transforms/moveCurrentBlockAfterPreviousSelectable.ts
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,37 @@ | ||
import { | ||
getBlockAbove, | ||
getPointBefore, | ||
getPreviousNode, | ||
isElement, | ||
isSelectionAtBlockStart, | ||
moveNodes, | ||
PlateEditor, | ||
} from '@udecode/plate-common'; | ||
|
||
import { isInClosedToggle } from '../queries'; | ||
|
||
// Return false only if the all previous blocks are not selectable | ||
export const moveCurrentBlockAfterPreviousSelectable = ( | ||
editor: PlateEditor | ||
): boolean | undefined => { | ||
const { selection } = editor; | ||
if (!selection) return; | ||
const aboveBlock = getBlockAbove(editor); | ||
if (!aboveBlock) return; | ||
if (!isSelectionAtBlockStart(editor)) return; | ||
const beforePoint = getPointBefore(editor, selection); | ||
if (!beforePoint) return; | ||
const blockBefore = getBlockAbove(editor, { at: beforePoint }); | ||
if (!blockBefore) return; | ||
if (!isInClosedToggle(editor, blockBefore[0].id)) return; // We're already after a selectable then | ||
const previousSelectableBlock = getPreviousNode(editor, { | ||
match: (node) => | ||
isElement(node) && !isInClosedToggle(editor, node.id as string), | ||
}); | ||
if (!previousSelectableBlock) return false; | ||
const afterSelectableBlock = [previousSelectableBlock[1][0] + 1]; | ||
moveNodes(editor, { | ||
at: aboveBlock[1], | ||
to: afterSelectableBlock, | ||
}); | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/toggle/src/transforms/moveNextSelectableAfterCurrentBlock.ts
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,35 @@ | ||
import { | ||
getBlockAbove, | ||
getNextNode, | ||
getPointAfter, | ||
isElement, | ||
isSelectionAtBlockEnd, | ||
moveNodes, | ||
PlateEditor, | ||
} from '@udecode/plate-common'; | ||
|
||
import { isInClosedToggle } from '../queries'; | ||
|
||
// Return false only if all next blocks are not selectable | ||
export const moveNextSelectableAfterCurrentBlock = (editor: PlateEditor) => { | ||
const { selection } = editor; | ||
if (!selection) return; | ||
const aboveBlock = getBlockAbove(editor); | ||
if (!aboveBlock) return; | ||
if (!isSelectionAtBlockEnd(editor)) return; | ||
const afterPoint = getPointAfter(editor, selection); | ||
if (!afterPoint) return; | ||
const blockAfter = getBlockAbove(editor, { at: afterPoint }); | ||
if (!blockAfter) return; | ||
if (!isInClosedToggle(editor, blockAfter[0].id)) return; // We're already before a selectable then | ||
const nextSelectableBlock = getNextNode(editor, { | ||
match: (node) => | ||
isElement(node) && !isInClosedToggle(editor, node.id as string), | ||
}); | ||
if (!nextSelectableBlock) return false; | ||
const afterCurrentBlock = [aboveBlock[1][0] + 1]; | ||
moveNodes(editor, { | ||
at: nextSelectableBlock[1], | ||
to: afterCurrentBlock, | ||
}); | ||
}; |
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