(type, index, assoc = 0, attributionManager = noAttributionsManager)
| 162 | * @function |
| 163 | */ |
| 164 | export 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…