MCPcopy Index your code
hub / github.com/yjs/yjs / createRelativePositionFromTypeIndex

Function createRelativePositionFromTypeIndex

src/utils/RelativePosition.js:164–187  ·  view source on GitHub ↗
(type, index, assoc = 0, attributionManager = noAttributionsManager)

Source from the content-addressed store, hash-verified

162 * @function
163 */
164export const createRelativePositionFromTypeIndex = (type, index, assoc = 0, attributionManager = noAttributionsManager) => {
165 let t = type._start
166 if (assoc < 0) {
167 // associated to the left character or the beginning of a type, increment index if possible.
168 if (index === 0) {
169 return createRelativePosition(type, null, assoc)
170 }
171 index--
172 }
173 while (t !== null) {
174 const len = attributionManager.contentLength(t)
175 if (len > index) {
176 // case 1: found position somewhere in the linked list
177 return createRelativePosition(type, createID(t.id.client, t.id.clock + index), assoc)
178 }
179 index -= len
180 if (t.right === null && assoc < 0) {
181 // left-associated position, return last available id
182 return createRelativePosition(type, t.lastId, assoc)
183 }
184 t = t.right
185 }
186 return createRelativePosition(type, null, assoc)
187}
188
189/**
190 * @param {encoding.Encoder} encoder

Callers

nothing calls this directly

Calls 3

createIDFunction · 0.90
createRelativePositionFunction · 0.85
contentLengthMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…