From eb06bc94aac424a9e976db3182e2348bf1d1a9da Mon Sep 17 00:00:00 2001 From: KushalLukhi Date: Fri, 20 Mar 2026 06:42:17 +0000 Subject: [PATCH] feat(editor): add prettify action to input editor toolbar --- components/EditorPanel.tsx | 27 +++++++++++++++++++++++++++ components/Monaco.tsx | 5 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/components/EditorPanel.tsx b/components/EditorPanel.tsx index 8c0ea14e..1eaef8e8 100644 --- a/components/EditorPanel.tsx +++ b/components/EditorPanel.tsx @@ -53,6 +53,7 @@ export default function EditorPanel({ acceptFiles, hasClear, hasCopy = true, + hasPrettier = true, topNotifications, language, defaultValue, @@ -63,6 +64,7 @@ export default function EditorPanel({ const [showSettingsDialogue, setSettingsDialog] = useState(false); const [value, setValue] = useState(defaultValue); const [fetchingUrl, setFetchingUrl] = useState(""); + const editorRef = useRef(null); const options = { fontSize: 14, @@ -137,6 +139,17 @@ export default function EditorPanel({ }); }, [value]); + const prettifyValue = useCallback(async () => { + if (!editorRef.current) return; + const action = editorRef.current.getAction("editor.action.formatDocument"); + if (!action) { + toaster.warning("Formatter not available for this input.", { id }); + return; + } + + await action.run(); + }, [id]); + const fetchFile = useCallback( close => { (async () => { @@ -255,6 +268,17 @@ export default function EditorPanel({ )} + {hasPrettier && editable && ( + + )} + {hasCopy && (