RangeRef API
4 min
rangeref objects keep a specific range in a document synced over time as new operations are applied to the editor it is created using the editor rangeref method 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 the affinity refers to the direction the rangeref will go when a user inserts content at the edges of the range inward means that the range tends to stay the same size when content is inserted at its edges, and outward meaans that the range tends to grow when content is inserted at its edges interface rangeref { current range | null affinity 'forward' | 'backward' | 'outward' | 'inward' | null unref() range | null } for example const selectionref = editor rangeref(editor, editor selection, { affinity 'inward', }) // allow the user to do stuff which might change the selection transforms unwrapnodes(editor) transforms select(editor, selectionref unref()) instance methods docid\ lhtqgojsfrimw zgzervcstatic methods docid\ lhtqgojsfrimw zgzervctransform methods docid\ lhtqgojsfrimw zgzervc 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