Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Oct 30, 2024
1 parent 9685493 commit 8b0b3e0
Showing 1 changed file with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function updateTables(
}

// retain
// eslint-disable-next-line max-lines-per-function

function updateCustomRanges(
body: IDocumentBody,
updateBody: IDocumentBody,
Expand Down Expand Up @@ -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<string>();
Expand All @@ -494,28 +494,22 @@ 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;
}
}

relativeCustomRanges.forEach((rangeId) => {
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;
}
Expand Down

0 comments on commit 8b0b3e0

Please sign in to comment.