From 70578877a03ce4ff30ec0f1662607282e48d45b3 Mon Sep 17 00:00:00 2001 From: durulkoca Date: Fri, 10 May 2024 16:51:17 +0900 Subject: [PATCH] Delete previous highlight before highlighting again --- src/components/ReadOnlyEditor/ReadOnlyEditor.jsx | 6 ++++++ src/lib/Project.js | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ReadOnlyEditor/ReadOnlyEditor.jsx b/src/components/ReadOnlyEditor/ReadOnlyEditor.jsx index c28df085..757eb9cd 100644 --- a/src/components/ReadOnlyEditor/ReadOnlyEditor.jsx +++ b/src/components/ReadOnlyEditor/ReadOnlyEditor.jsx @@ -1,10 +1,13 @@ import "highlight.js/styles/github-dark.css"; + import EditIcon from "@mui/icons-material/Edit"; import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import hljs from "highlight.js"; + import { Box, Collapse, IconButton, Stack, Typography } from "@mui/material"; import React, { useEffect, useRef, useState } from "react"; + import * as prettierStandalone from "prettier/standalone"; import * as typescriptPlugin from "prettier/parser-typescript"; @@ -20,6 +23,9 @@ const ReadOnlyEditor = ({ useEffect(() => { if (codeRef.current) { + if (codeRef.current.dataset.highlighted === "yes") { + delete codeRef.current.dataset.highlighted; + } hljs.highlightElement(codeRef.current); } }, [language, value]); diff --git a/src/lib/Project.js b/src/lib/Project.js index b72aa5be..943cafff 100644 --- a/src/lib/Project.js +++ b/src/lib/Project.js @@ -276,7 +276,12 @@ function compile(blocks) { const api = createAPI(uniqueFunctions); api.unshift(rootObject); - return { api, functions: uniqueFunctions, declarations, imperatives }; + return { + api, + functions: uniqueFunctions, + declarations: uniqueDeclarations, + imperatives, + }; } export default { compile };