diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index 0b569b8da..32d411244 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -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 hyperscript tag must have an 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 hyperscript tag must have a tag as a child with \`path\` and \`offset\` attributes defined.` ) diff --git a/packages/slate-hyperscript/test/fixtures/selection-offset-start.js b/packages/slate-hyperscript/test/fixtures/selection-offset-start.js new file mode 100644 index 000000000..d00277152 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/selection-offset-start.js @@ -0,0 +1,35 @@ +/** @jsx jsx */ + +import { jsx } from 'slate-hyperscript' + +export const input = ( + + word + + + + + +) + +export const output = { + children: [ + { + children: [ + { + text: 'word', + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [0, 0], + offset: 0, + }, + }, +}