From 2c7630c286dd8d3b40682fcf390b92c9b761430f Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Sun, 5 Jan 2025 03:05:19 +0800 Subject: [PATCH] feat(playground): enhance PlaygroundPage with Monaco editor focus and position handling --- src/app/playground/page.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/playground/page.tsx b/src/app/playground/page.tsx index eb90ea8..e04d08c 100644 --- a/src/app/playground/page.tsx +++ b/src/app/playground/page.tsx @@ -1,6 +1,7 @@ "use client"; -import { useState } from "react"; +import * as monaco from "monaco-editor"; +import { useRef, useState } from "react"; import { Editor } from "@monaco-editor/react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; @@ -39,6 +40,7 @@ int main() { }; export default function PlaygroundPage() { + const editorRef = useRef(null); const [language, setLanguage] = useState("c"); const file = files[language]; @@ -98,6 +100,20 @@ export default function PlaygroundPage() { defaultLanguage={file.language} defaultValue={file.value} options={{ automaticLayout: true }} + onMount={(editor) => { + editorRef.current = editor; + const model = editor.getModel(); + if (model) { + const lineCount = model.getLineCount(); + const lastLineLength = model.getLineLength(lineCount); + editor.setPosition({ + lineNumber: lineCount, + column: lastLineLength + 1, + }); + editor.focus(); + console.log(editor.getModel()?.uri.path); + } + }} /> );