Skip to content

Commit 38735d7

Browse files
author
iamhyc
committed
chore: temp update
1 parent 9446d88 commit 38735d7

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/collaboration/reviewPanelProvider.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ class EditManager {
255255
return this.applyInterleavedRangeWithDeleteChange(text, edit, before);
256256
}
257257
});
258-
// 1b.2. notify the removal or create text range
258+
// 1b.2. extend `beginRemain` with intermediate text range if is instanceof `TextChange`
259+
if (beginRemain instanceof TextChange) {
260+
//TODO: clip the intermediate text and append
261+
//TODO: calculate the offset of position
262+
}
263+
// 1b.3. notify the removal or create text range
259264
[ [beginText,beginRemain], [endText,endRemain] ].map(([text,remain]) => {
260265
if (text instanceof TextChange && remain instanceof ChangeRange) {
261266
refreshes.push({id:text.change.id});
@@ -264,7 +269,7 @@ class EditManager {
264269
refreshes.push({id:remain.change.id, type:'deleteChange'});
265270
}
266271
});
267-
// 1b.3. merge the remains of `begin` and `end` text ranges, if they are the same type
272+
// 1b.4. merge the remains of `begin` and `end` text ranges, if they are the same type (FIXME: need double check for tcId condition)
268273
if (beginRemain instanceof TextChange && endRemain instanceof TextChange && beginRemain.isInsert===endRemain.isInsert) {
269274
const oldRemain = beginRemain < endRemain? beginRemain : endRemain;
270275
const newRemain = oldRemain===beginRemain? endRemain : beginRemain;
@@ -280,10 +285,10 @@ class EditManager {
280285
this.wholeText.remove(newRemain);
281286
refreshes.push({id:newRemain.change.id});
282287
}
283-
// 1b.4 remove intermediate text ranges
288+
// 1b.5 remove intermediate text ranges
284289
this.wholeText.removeBetween(beginText, endText);
285290
}
286-
// 2. update position offset for the range after `end`
291+
// 2. update position offset for the range after `end` (FIXME: need double check for tcId condition)
287292
this.wholeText.apply(endText, (text) => {
288293
text.op.p += edit.op.i!.length - edit.op.d!.length;
289294
});
@@ -354,15 +359,16 @@ class EditManager {
354359
}
355360

356361
applyInsertRangeWithDeleteChange(text: EditChange, edit: EditChange, before:boolean) {
362+
// clip the text range
357363
if (before) {
358-
const offset = text.begin - edit.begin;
364+
const offset = text.end - edit.begin;
359365
text.op.i = text.op.i!.slice(0, offset);
360366
} else {
361-
const offset = edit.end - text.end;
367+
const offset = edit.end - text.begin;
362368
text.op.p -= offset;
363369
text.op.i = text.op.i!.slice(offset);
364370
}
365-
//
371+
// return the remain text range if it's not empty
366372
if (text.op.i) {
367373
return text;
368374
} else {
@@ -371,38 +377,29 @@ class EditManager {
371377
}
372378

373379
applyDeleteRangeWithDeleteChange(text: EditChange, edit: EditChange, before:boolean) {
374-
// extend the text range with `tc`
375-
if (edit.change?.id) {
376-
if (before) {
377-
text.op.d = edit.op.d + text.op.d!;
378-
} else {
379-
text.op.d = text.op.d! + edit.op.d;
380-
}
381-
}
382-
// offset the `before` text range
383-
else if (before) {
384-
text.op.p -= edit.begin - text.begin;
385-
}
380+
// do nothing
386381
return text;
387382
}
388383

389384
applyInterleavedRangeWithDeleteChange(text: ChangeRange, edit: EditChange, before:boolean) {
390385
// create new text range with `tc`
391386
if (edit.change?.id) {
392-
const newId = generateTrackId();
393-
const offset = before? text.begin-edit.begin : edit.end-text.end;
387+
const offset = before? text.end-edit.begin : edit.end-text.begin;
394388
const newText = new TextChange({
395-
id: newId,
389+
id: edit.change.id,
396390
op: {
397391
p: before? text.end : text.begin+offset,
398-
d: before? edit.op.d!.slice(0, offset) : edit.op.d!.slice(offset),
392+
d: before? edit.op.d!.slice(0, offset) : edit.op.d!.slice(edit.op.d!.length-offset),
399393
},
400394
metadata: this.metadata,
401395
});
402396
this.wholeText.insert(newText);
403397
return newText;
404398
}
405-
return new ChangeRange();
399+
// else return empty range
400+
else {
401+
return new ChangeRange();
402+
}
406403
}
407404
}
408405

0 commit comments

Comments
 (0)