mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 18:24:03 +02:00
Allow zero as offset on <anchor> and <focus> inside <selection> (#3491)
* Allow zero as offset on <anchor> and <focus> inside <selection> When creating a selection using the <selection> hyperscript tag, you couldn't set zero as offset on <anchor> and <focus>, because of a faulty falsiness check. This is fixed by checking if the offset is falsy and explicitly not zero. * Make sure offset can't be null or undefined on <anchor> and <focus> Throw exception when offset is strictly null or undefined, on <anchor> and <focus> when creating a <selection>.
This commit is contained in:
committed by
GitHub
parent
30bc30df4b
commit
eb181f3279
@@ -152,13 +152,13 @@ export function createSelection(
|
||||
const anchor: AnchorToken = children.find(c => c instanceof AnchorToken)
|
||||
const focus: FocusToken = children.find(c => c instanceof FocusToken)
|
||||
|
||||
if (!anchor || !anchor.offset || !anchor.path) {
|
||||
if (!anchor || anchor.offset == null || anchor.path == null) {
|
||||
throw new Error(
|
||||
`The <selection> hyperscript tag must have an <anchor> tag as a child with \`path\` and \`offset\` attributes defined.`
|
||||
)
|
||||
}
|
||||
|
||||
if (!focus || !focus.offset || !focus.path) {
|
||||
if (!focus || focus.offset == null || focus.path == null) {
|
||||
throw new Error(
|
||||
`The <selection> hyperscript tag must have a <focus> tag as a child with \`path\` and \`offset\` attributes defined.`
|
||||
)
|
||||
|
Reference in New Issue
Block a user