|
1 | 1 | import {Point} from '../point/Point'; |
2 | 2 | import {Anchor} from '../constants'; |
3 | | -import {type ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; |
| 3 | +import type {ITimestampStruct} from '../../../json-crdt-patch/clock'; |
4 | 4 | import type {Printable} from '../../../util/print/types'; |
5 | 5 | import type {AbstractRga, Chunk} from '../../../json-crdt/nodes/rga'; |
6 | 6 |
|
@@ -161,72 +161,8 @@ export class Range<T = string> implements Printable { |
161 | 161 | * (2) anchors of non-deleted adjacent chunks. |
162 | 162 | */ |
163 | 163 | public expand(): void { |
164 | | - this.expandStart(); |
165 | | - this.expandEnd(); |
166 | | - } |
167 | | - |
168 | | - public expandStart(): void { |
169 | | - const {start, rga: rga} = this; |
170 | | - let chunk = start.chunk(); |
171 | | - if (!chunk) return; |
172 | | - if (!chunk.del) { |
173 | | - if (start.anchor === Anchor.After) return; |
174 | | - const pointIsStartOfChunk = start.id.time === chunk.id.time; |
175 | | - if (!pointIsStartOfChunk) { |
176 | | - start.id = tick(start.id, -1); |
177 | | - start.anchor = Anchor.After; |
178 | | - return; |
179 | | - } |
180 | | - } |
181 | | - while (chunk) { |
182 | | - const prev = rga.prev(chunk); |
183 | | - if (!prev) { |
184 | | - start.id = chunk.id; |
185 | | - start.anchor = Anchor.Before; |
186 | | - break; |
187 | | - } else { |
188 | | - if (prev.del) { |
189 | | - chunk = prev; |
190 | | - continue; |
191 | | - } else { |
192 | | - start.id = prev.span > 1 ? tick(prev.id, prev.span - 1) : prev.id; |
193 | | - start.anchor = Anchor.After; |
194 | | - break; |
195 | | - } |
196 | | - } |
197 | | - } |
198 | | - } |
199 | | - |
200 | | - public expandEnd(): void { |
201 | | - const {end, rga: rga} = this; |
202 | | - let chunk = end.chunk(); |
203 | | - if (!chunk) return; |
204 | | - if (!chunk.del) { |
205 | | - if (end.anchor === Anchor.Before) return; |
206 | | - const pointIsEndOfChunk = end.id.time === chunk.id.time + chunk.span - 1; |
207 | | - if (!pointIsEndOfChunk) { |
208 | | - end.id = tick(end.id, 1); |
209 | | - end.anchor = Anchor.Before; |
210 | | - return; |
211 | | - } |
212 | | - } |
213 | | - while (chunk) { |
214 | | - const next = rga.next(chunk); |
215 | | - if (!next) { |
216 | | - end.id = chunk.span > 1 ? tick(chunk.id, chunk.span - 1) : chunk.id; |
217 | | - end.anchor = Anchor.After; |
218 | | - break; |
219 | | - } else { |
220 | | - if (next.del) { |
221 | | - chunk = next; |
222 | | - continue; |
223 | | - } else { |
224 | | - end.id = next.id; |
225 | | - end.anchor = Anchor.Before; |
226 | | - break; |
227 | | - } |
228 | | - } |
229 | | - } |
| 164 | + this.start.refAfter(); |
| 165 | + this.end.refBefore(); |
230 | 166 | } |
231 | 167 |
|
232 | 168 | // -------------------------------------------------- View coordinate methods |
|
0 commit comments