From 9022665e4c67a29f1cd3e1680b313d2f7b49c3a9 Mon Sep 17 00:00:00 2001 From: anastasiia Date: Wed, 2 Aug 2023 13:00:24 +0300 Subject: [PATCH] fix overlapping highlights --- .../CodeBlock/CodeFull/CodeContainerFull.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/src/components/CodeBlock/CodeFull/CodeContainerFull.tsx b/client/src/components/CodeBlock/CodeFull/CodeContainerFull.tsx index dd698b4e83..b88edada9a 100644 --- a/client/src/components/CodeBlock/CodeFull/CodeContainerFull.tsx +++ b/client/src/components/CodeBlock/CodeFull/CodeContainerFull.tsx @@ -124,9 +124,15 @@ const CodeContainerFull = ({ return (
{tokens.map((line, index) => { - let highlightForLine = highlights?.findIndex( - (h) => h && index >= h.lines[0] && index <= h.lines[1], - ); + let highlightForLine = highlights + ?.sort((a, b) => + a && + b && + a?.lines?.[1] - a?.lines?.[0] < b?.lines?.[1] - b?.lines?.[0] + ? -1 + : 1, + ) + .findIndex((h) => h && index >= h.lines[0] && index <= h.lines[1]); if (highlightForLine && highlightForLine < 0) { highlightForLine = undefined; }