{"record":{"id":"8aa12748f751cd0d","repo":"ianstormtaylor/slate","slug":"when-setting-the-selection-and-the-current-selecti","errorCode":null,"errorMessage":"When setting the selection and the current selection is \\`null\\` you must provide at least an \\`anchor\\` and \\`focus\\`, but you passed: ${Scrubber.stringify(\n        target\n      )}","messagePattern":"When setting the selection and the current selection is \\\\`null\\\\` you must provide at least an \\\\`anchor\\\\` and \\\\`focus\\\\`, but you passed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/transforms-selection/select.ts","lineNumber":17,"sourceCode":"import { SelectionTransforms } from '../interfaces/transforms/selection'\nimport { Editor } from '../interfaces/editor'\nimport { Transforms } from '../interfaces/transforms'\nimport { Scrubber } from '../interfaces/scrubber'\nimport { Location } from '../interfaces'\n\nexport const select: SelectionTransforms['select'] = (editor, target) => {\n  const { selection } = editor\n  target = Editor.range(editor, target)\n\n  if (selection) {\n    Transforms.setSelection(editor, target)\n    return\n  }\n\n  if (!Location.isRange(target)) {\n    throw new Error(\n      `When setting the selection and the current selection is \\`null\\` you must provide at least an \\`anchor\\` and \\`focus\\`, but you passed: ${Scrubber.stringify(\n        target\n      )}`\n    )\n  }\n\n  editor.apply({\n    type: 'set_selection',\n    properties: selection,\n    newProperties: target,\n  })\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/transforms-selection/select.ts#L1-L30","documentation":"select() (Transforms.select) requires a full Range when the current editor selection is null, because there is nothing to derive the missing bound from. The target must be a complete Range with both anchor and focus (or a Point/Path which converts to one); a partial object like {anchor} alone is rejected.","triggerScenarios":"Transforms.select(editor, { anchor: point }) with selection null; passing a partial Range-like object when the editor was never selected or after deselect(); passing a malformed target (string, number, or object missing anchor/focus).","commonSituations":"Restoring a saved selection from localStorage where focus was dropped; programmatic focus-after-mount before any user selection; spread of optional props producing an incomplete range.","solutions":["Pass a complete Range {anchor, focus}, or a Point/Path/Range object created via Range.isRange-valid data","Use Point refs or Editor.point(editor, at) to build a valid full target","If target may be partial, merge it with editor.selection when it exists, else require both bounds"],"exampleFix":"// before\nTransforms.select(editor, { anchor }) // selection is null, focus missing\n\n// after\nTransforms.select(editor, { anchor, focus: anchor })","handlingStrategy":"type-guard","validationCode":"if (editor.selection == null && !Range.isRange(target)) {\n  throw new Error('Provide a full Range when selection is null')\n}\nTransforms.select(editor, target)","typeGuard":"const isSelectableTarget = (t: unknown): t is Range | Point =>\n  Range.isRange(t) || Point.isPoint(t) || Path.isPath(t)","tryCatchPattern":null,"preventionTips":["Always pass {anchor, focus} (or a Point/Path) to Transforms.select","Validate persisted selections with Range.isRange before restoring","Default missing focus to the anchor value"],"tags":["selection","select","range","validation","slate"],"backgroundTag":"invalid-selection-state","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}