diff --git a/frontend/src/routes/_oh.app._index/code-editor-component.tsx b/frontend/src/routes/_oh.app._index/code-editor-component.tsx index cf94ed863a4..c18c023fec7 100644 --- a/frontend/src/routes/_oh.app._index/code-editor-component.tsx +++ b/frontend/src/routes/_oh.app._index/code-editor-component.tsx @@ -1,5 +1,5 @@ import { Editor, Monaco } from "@monaco-editor/react"; -import React from "react"; +import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { VscCode } from "react-icons/vsc"; import { type editor } from "monaco-editor"; @@ -22,6 +22,8 @@ function CodeEditorCompoonent({ isReadOnly }: CodeEditorCompoonentProps) { saveFileContent: saveNewFileContent, } = useFiles(); + const [cursorPosition, setCursorPosition] = useState({ line: 1, column: 1 }); + const handleEditorDidMount = React.useCallback( (editor: editor.IStandaloneCodeEditor, monaco: Monaco): void => { monaco.editor.defineTheme("my-theme", { @@ -34,6 +36,13 @@ function CodeEditorCompoonent({ isReadOnly }: CodeEditorCompoonentProps) { }); monaco.editor.setTheme("my-theme"); + + editor.onDidChangeCursorPosition((e) => { + setCursorPosition({ + line: e.position.lineNumber, + column: e.position.column, + }); + }); }, [], ); @@ -62,7 +71,7 @@ function CodeEditorCompoonent({ isReadOnly }: CodeEditorCompoonentProps) { return () => { document.removeEventListener("keydown", handleSave); }; - }, [saveNewFileContent]); + }, [saveNewFileContent, selectedPath]); if (!selectedPath) { return ( @@ -77,20 +86,29 @@ function CodeEditorCompoonent({ isReadOnly }: CodeEditorCompoonentProps) { } return ( - +
+ {/* Ensure that the editor takes up the maximum amount of space in the parent container */} +
+ +
+ {/* cursor position information */} +
+ Row: {cursorPosition.line}, Column: {cursorPosition.column} +
+
); }