diff --git a/apps/renderer/src/modules/editor/css-editor.tsx b/apps/renderer/src/modules/editor/css-editor.tsx index f84432f8b..f3e1c1983 100644 --- a/apps/renderer/src/modules/editor/css-editor.tsx +++ b/apps/renderer/src/modules/editor/css-editor.tsx @@ -20,7 +20,7 @@ export const CSSEditor: Component<{ const ref = useRef(null) const isDark = useIsDark() - const updateFnRef = useRef<() => void>() + useLayoutEffect(() => { let dispose: () => void if (ref.current) { @@ -34,7 +34,7 @@ export const CSSEditor: Component<{ selection?.addRange(range) ref.current.textContent = defaultValue ?? "" - const { dispose: disposeShiki, update } = createPlainShiki(shiki).mount(ref.current, { + const { dispose: disposeShiki } = createPlainShiki(shiki).mount(ref.current, { lang: "css", themes: { light: "github-light", @@ -42,7 +42,7 @@ export const CSSEditor: Component<{ }, defaultTheme: isDark ? "dark" : "light", }) - updateFnRef.current = update + dispose = disposeShiki } return () => dispose?.() @@ -70,50 +70,10 @@ export const CSSEditor: Component<{ }) }, }) - const handleCopy = useEventCallback((e: React.ClipboardEvent) => { - e.preventDefault() - e.clipboardData.setData("text/plain", ref.current?.textContent ?? "") - }) - const handlePaste = useEventCallback((e: React.ClipboardEvent) => { - e.preventDefault() - const text = e.clipboardData.getData("text/plain") - - const selection = window.getSelection() - if (selection && selection.rangeCount > 0) { - const range = selection.getRangeAt(0) - // Delete the current selection - range.deleteContents() - // Insert the text at the current cursor position - range.insertNode(document.createTextNode(text)) - - range.setStartAfter(range.endContainer) - range.setEndAfter(range.endContainer) - selection.removeAllRanges() - selection.addRange(range) - } - updateFnRef.current?.() + const handleInput = useEventCallback(() => { onChange(ref.current?.textContent ?? "") - // Focus the editor and set cursor to the end - if (ref.current) { - ref.current.focus() - const selection = window.getSelection() - const range = document.createRange() - range.selectNodeContents(ref.current) - range.collapse(false) // collapse to end - selection?.removeAllRanges() - selection?.addRange(range) - - // Get selection position - const rect = range.getBoundingClientRect() - const containerRect = ref.current.getBoundingClientRect() - const relativeBottom = rect.bottom - containerRect.top - - // If out of view, scroll to the position - if (relativeBottom > ref.current.clientHeight) { - ref.current.scrollTop += relativeBottom - ref.current.clientHeight - } - } }) + return (
diff --git a/apps/renderer/src/modules/settings/tabs/apperance.tsx b/apps/renderer/src/modules/settings/tabs/apperance.tsx index 633936363..a42e177cc 100644 --- a/apps/renderer/src/modules/settings/tabs/apperance.tsx +++ b/apps/renderer/src/modules/settings/tabs/apperance.tsx @@ -313,7 +313,7 @@ const CustomCSS = () => { resizeable: true, resizeDefaultSize: { width: 700, - height: 400, + height: window.innerHeight - 200, }, }) }}