docs/api/slate/location-ref.mdx
Location references are objects that keep specific locations (paths, points, or ranges) in a document synced over time as new operations are applied to the editor. You can access their current property at any time for the up-to-date location value. You can access their current property at any time for the up-to-date location value.
PathRefPath reference objects keep a specific path in a document synced over time. Created using editor.api.pathRef.
PointRefPoint reference objects keep a specific point in a document synced over time. Created using editor.api.pointRef.
RangeRefRange reference objects keep a specific range in a document synced over time. Created using editor.api.rangeRef.
Example usage of a RangeRef:
const selectionRef = editor.api.rangeRef(editor.selection, {
affinity: 'inward',
})
// Operations that might change the selection
Transforms.unwrapNodes(editor)
// Restore the selection using the ref
Transforms.select(editor, selectionRef.unref())
PathRefApitransformTransform a path reference by an operation.
<API name="transform"> <APIParameters> <APIItem name="ref" type="PathRef"> The path reference to transform. </APIItem> <APIItem name="op" type="Operation"> The operation to apply. The editor calls this automatically as needed. </APIItem> </APIParameters> </API>PointRefApitransformTransform a point reference by an operation.
<API name="transform"> <APIParameters> <APIItem name="ref" type="PointRef"> The point reference to transform. </APIItem> <APIItem name="op" type="Operation"> The operation to apply. The editor calls this automatically as needed. </APIItem> </APIParameters> </API>RangeRefApitransformTransform a range reference by an operation.
<API name="transform"> <APIParameters> <APIItem name="ref" type="RangeRef"> The range reference to transform. </APIItem> <APIItem name="op" type="Operation"> The operation to apply. The editor calls this automatically as needed. </APIItem> </APIParameters> </API>