diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index fb256082b..94120b216 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -118,6 +118,14 @@ export const Path = { ) }, + /** + * Check if the path of previous sibling node exists + */ + + hasPrevious(path: Path): boolean { + return path[path.length - 1] > 0 + }, + /** * Check if a path is after another. */ diff --git a/packages/slate/test/interfaces/Path/hasPrevious/root.tsx b/packages/slate/test/interfaces/Path/hasPrevious/root.tsx new file mode 100644 index 000000000..827d102e8 --- /dev/null +++ b/packages/slate/test/interfaces/Path/hasPrevious/root.tsx @@ -0,0 +1,7 @@ +import { Path } from 'slate' + +export const input = [0, 0] +export const test = path => { + return Path.hasPrevious(path) +} +export const output = false diff --git a/packages/slate/test/interfaces/Path/hasPrevious/success.tsx b/packages/slate/test/interfaces/Path/hasPrevious/success.tsx new file mode 100644 index 000000000..76e772bd4 --- /dev/null +++ b/packages/slate/test/interfaces/Path/hasPrevious/success.tsx @@ -0,0 +1,7 @@ +import { Path } from 'slate' + +export const input = [0, 1] +export const test = path => { + return Path.hasPrevious(path) +} +export const output = true