From 58249210567c00a6e56b129cebe7cb319555347a Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 26 Nov 2024 20:01:02 +0800 Subject: [PATCH] fix(css-editor): Compatible with browsers that do not support plaintext-only Signed-off-by: Innei --- .../src/modules/editor/css-editor.tsx | 43 ++++++++++++++++++- packages/components/src/ui/input/TextArea.tsx | 4 +- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/apps/renderer/src/modules/editor/css-editor.tsx b/apps/renderer/src/modules/editor/css-editor.tsx index f3e1c1983..c3777c557 100644 --- a/apps/renderer/src/modules/editor/css-editor.tsx +++ b/apps/renderer/src/modules/editor/css-editor.tsx @@ -1,8 +1,9 @@ +import { TextArea } from "@follow/components/ui/input/TextArea.js" import { useInputComposition, useIsDark } from "@follow/hooks" import { nextFrame } from "@follow/utils/dom" import { cn } from "@follow/utils/utils" import { createPlainShiki } from "plain-shiki" -import { useLayoutEffect, useRef } from "react" +import { useLayoutEffect, useMemo, useRef } from "react" import css from "shiki/langs/css.mjs" import githubDark from "shiki/themes/github-dark.mjs" import githubLight from "shiki/themes/github-light.mjs" @@ -13,6 +14,7 @@ import { shiki } from "~/components/ui/code-highlighter/shiki/shared" shiki.loadLanguageSync(css) shiki.loadThemeSync(githubDark) shiki.loadThemeSync(githubLight) + export const CSSEditor: Component<{ onChange: (value: string) => void defaultValue?: string @@ -74,6 +76,26 @@ export const CSSEditor: Component<{ onChange(ref.current?.textContent ?? "") }) + const isSupportPlainTextOnly = useIsSupportPlainTextOnly() + if (!isSupportPlainTextOnly) { + return ( +
+
+ + Your browser does not support highlight CSS. +
+
+
+