RangeRef
RangeRef objects keep a specific range in a document synced over time as new operations are applied to the editor. You can access their property current at any time for the up-to-date Range value. When you no longer need to track this location, call unref() to free the resources.
1
interface RangeRef {
2
current: Range | null
3
affinity: 'forward' | 'backward' | 'outward' | 'inward' | null
4
unref(): Range | null
5
}
Copied!
For example:
1
const selectionRef = Editor.rangeRef(editor, editor.selection, {
2
affinity: 'inward',
3
})
4
// Allow the user to do stuff which might change the selection
5
Transforms.unwrapNodes(editor)
6
Transforms.select(editor, selectionRef.unRef())
Copied!

Instance methods

unRef() => Range

Call this when you no longer need to sync this range. It also returns the current value.

Static methods

Transform methods

RangeRef.transform(ref: RangeRef, op: Operation)

Transform the range refs current value by an op. The editor calls this as needed, so normally you won't need to.
Last modified 1mo ago