diff --git a/web/src/beta/features/Editor/Map/LayerStylePanel/Editor/StyleCode/index.tsx b/web/src/beta/features/Editor/Map/LayerStylePanel/Editor/StyleCode/index.tsx index 3d8f91acb0..8598c58638 100644 --- a/web/src/beta/features/Editor/Map/LayerStylePanel/Editor/StyleCode/index.tsx +++ b/web/src/beta/features/Editor/Map/LayerStylePanel/Editor/StyleCode/index.tsx @@ -2,7 +2,7 @@ import { CodeInput } from "@reearth/beta/lib/reearth-ui"; import { LayerStyle } from "@reearth/services/api/layerStyleApi/utils"; import { styled } from "@reearth/services/theme"; import { SetStateAction } from "jotai"; -import { Dispatch, FC, useCallback, useEffect, useState } from "react"; +import { Dispatch, FC, useCallback, useEffect, useRef, useState } from "react"; import NoStyleMessage from "../NoStyleMessage"; @@ -13,36 +13,34 @@ type CodeProps = { const StyleCode: FC = ({ layerStyle, setLayerStyle }) => { const [styleCode, setStyleCode] = useState(""); + const styleCodeRef = useRef(styleCode); + styleCodeRef.current = styleCode; useEffect(() => { setStyleCode(JSON.stringify(layerStyle?.value, null, 2)); }, [layerStyle]); - const handleStyleCodeChange = useCallback( - (newStyleCode?: string) => { - try { - const parsedStyle = JSON.parse(newStyleCode || ""); - setLayerStyle((prev) => { - if (!prev?.id) return prev; - return { - ...prev, - value: parsedStyle - }; - }); - } catch (_error) { - // Do nothing - } - - setStyleCode(newStyleCode); - }, - [setLayerStyle] - ); + const updateStyle = useCallback(() => { + try { + const parsedStyle = JSON.parse(styleCodeRef.current || ""); + setLayerStyle((prev) => { + if (!prev?.id) return prev; + return { + ...prev, + value: parsedStyle + }; + }); + } catch (_error) { + // Do nothing + } + }, [setLayerStyle]); return layerStyle?.id ? ( diff --git a/web/src/beta/lib/reearth-ui/components/CodeInput/index.tsx b/web/src/beta/lib/reearth-ui/components/CodeInput/index.tsx index 9f90b5ca03..c0806dc4ff 100644 --- a/web/src/beta/lib/reearth-ui/components/CodeInput/index.tsx +++ b/web/src/beta/lib/reearth-ui/components/CodeInput/index.tsx @@ -45,7 +45,8 @@ export const CodeInput: FC = ({ }, scrollbar: { horizontal: "hidden" - } + }, + tabSize: 2 }), [disabled, showLines] );