From 8b0b3e00581721f99831aae49da13969ba1267c2 Mon Sep 17 00:00:00 2001 From: zhangw Date: Wed, 30 Oct 2024 22:15:50 +0800 Subject: [PATCH] feat: update --- .../text-x/apply-utils/update-apply.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/core/src/docs/data-model/text-x/apply-utils/update-apply.ts b/packages/core/src/docs/data-model/text-x/apply-utils/update-apply.ts index eac82e48935..737600cc5c0 100644 --- a/packages/core/src/docs/data-model/text-x/apply-utils/update-apply.ts +++ b/packages/core/src/docs/data-model/text-x/apply-utils/update-apply.ts @@ -436,7 +436,7 @@ function updateTables( } // retain -// eslint-disable-next-line max-lines-per-function + function updateCustomRanges( body: IDocumentBody, updateBody: IDocumentBody, @@ -469,11 +469,11 @@ function updateCustomRanges( updateBody.customRanges?.forEach((customRange) => { const { startIndex, endIndex } = customRange; - customRanges.push({ + rangeMap[customRange.rangeId] = { ...customRange, startIndex: startIndex + currentIndex, endIndex: endIndex + currentIndex, - }); + }; }); } else { const relativeCustomRanges = new Set(); @@ -494,11 +494,12 @@ function updateCustomRanges( if (oldCustomRange) { if (updateCustomRange.rangeType === CustomRangeType.DELTED) { removeCustomRanges.push(oldCustomRange); + delete rangeMap[rangeId]; continue; } Object.assign(oldCustomRange, updateCustomRange); } else { - customRanges.push(updateCustomRange); + rangeMap[rangeId] = updateCustomRange; } } @@ -506,16 +507,9 @@ function updateCustomRanges( removeCustomRanges.push(rangeMap[rangeId]); delete rangeMap[rangeId]; }); - - for (const removeCustomRange of removeCustomRanges) { - const { rangeId } = removeCustomRange; - const index = customRanges.findIndex((r) => r.rangeId === rangeId); - if (index !== -1) { - customRanges.splice(index, 1); - } - } } + body.customRanges = Object.values(rangeMap); body.customRanges.sort((a, b) => a.startIndex - b.startIndex); return removeCustomRanges; }