From ec574d0ad995b2b768e27082fe22063cf2ab837f Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 18 Aug 2023 13:54:38 +0800 Subject: [PATCH] use new color or the color of the last overlap highlight when merging highlights --- packages/api/src/resolvers/highlight/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/api/src/resolvers/highlight/index.ts b/packages/api/src/resolvers/highlight/index.ts index 1ca5ee8c5..ff4eb1f42 100644 --- a/packages/api/src/resolvers/highlight/index.ts +++ b/packages/api/src/resolvers/highlight/index.ts @@ -148,6 +148,7 @@ export const mergeHighlightResolver = authorized< /* Compute merged annotation form the order of highlights appearing on page */ const mergedAnnotations: string[] = [] const mergedLabels: Label[] = [] + const mergedColors: string[] = [] const pageHighlights = page.highlights.filter((highlight) => { // filter out highlights that are in the overlap list // and are of type highlight (not annotation or note) @@ -168,10 +169,15 @@ export const mergeHighlightResolver = authorized< } }) } + // collect colors of overlap highlights + highlight.color && mergedColors.push(highlight.color) + return false } return true }) + // use new color or the color of the last overlap highlight + const color = newHighlightInput.color || mergedColors[mergedColors.length - 1] try { const highlight: HighlightData = { ...newHighlightInput, @@ -182,7 +188,7 @@ export const mergeHighlightResolver = authorized< mergedAnnotations.length > 0 ? mergedAnnotations.join('\n') : null, type: HighlightType.Highlight, labels: mergedLabels, - color: newHighlightInput.color || pageHighlights[0].color, // use new color or the color of the first highlight + color, } const merged = await updatePage(