remove unnecessary height and width from codeeditor

This commit is contained in:
Evan Simkowitz 2024-09-04 11:45:26 -07:00
parent 0413b240dd
commit 2cc0fdc999
No known key found for this signature in database
2 changed files with 2 additions and 12 deletions

View File

@ -1,8 +1,6 @@
// Copyright 2024, Command Line Inc. // Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { useHeight } from "@/app/hook/useHeight";
import { useWidth } from "@/app/hook/useWidth";
import loader from "@monaco-editor/loader"; import loader from "@monaco-editor/loader";
import { Editor, Monaco } from "@monaco-editor/react"; import { Editor, Monaco } from "@monaco-editor/react";
import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api"; import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api";
@ -66,7 +64,6 @@ function defaultEditorOptions(): MonacoTypes.editor.IEditorOptions {
} }
interface CodeEditorProps { interface CodeEditorProps {
parentRef: React.MutableRefObject<HTMLDivElement>;
text: string; text: string;
filename: string; filename: string;
language?: string; language?: string;
@ -74,11 +71,9 @@ interface CodeEditorProps {
onMount?: (monacoPtr: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco) => () => void; onMount?: (monacoPtr: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco) => () => void;
} }
export function CodeEditor({ parentRef, text, language, filename, onChange, onMount }: CodeEditorProps) { export function CodeEditor({ text, language, filename, onChange, onMount }: CodeEditorProps) {
const divRef = useRef<HTMLDivElement>(null); const divRef = useRef<HTMLDivElement>(null);
const unmountRef = useRef<() => void>(null); const unmountRef = useRef<() => void>(null);
const parentHeight = useHeight(parentRef);
const parentWidth = useWidth(parentRef);
const theme = "wave-theme-dark"; const theme = "wave-theme-dark";
React.useEffect(() => { React.useEffect(() => {
@ -111,8 +106,6 @@ export function CodeEditor({ parentRef, text, language, filename, onChange, onMo
theme={theme} theme={theme}
value={text} value={text}
options={editorOpts} options={editorOpts}
height={parentHeight}
width={parentWidth}
onChange={handleEditorChange} onChange={handleEditorChange}
onMount={handleEditorOnMount} onMount={handleEditorOnMount}
path={filename} path={filename}

View File

@ -691,7 +691,7 @@ function StreamingPreview({ model }: SpecializedViewProps) {
return <CenteredDiv>Preview Not Supported</CenteredDiv>; return <CenteredDiv>Preview Not Supported</CenteredDiv>;
} }
function CodeEditPreview({ parentRef, model }: SpecializedViewProps) { function CodeEditPreview({ model }: SpecializedViewProps) {
const fileContent = jotai.useAtomValue(model.fileContent); const fileContent = jotai.useAtomValue(model.fileContent);
const setNewFileContent = jotai.useSetAtom(model.newFileContent); const setNewFileContent = jotai.useSetAtom(model.newFileContent);
const fileName = jotai.useAtomValue(model.statFilePath); const fileName = jotai.useAtomValue(model.statFilePath);
@ -723,8 +723,6 @@ function CodeEditPreview({ parentRef, model }: SpecializedViewProps) {
function onMount(editor: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco): () => void { function onMount(editor: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco): () => void {
model.monacoRef.current = editor; model.monacoRef.current = editor;
const simpleMod = keyutil.getKeyUtilPlatform() == "darwin" ? monaco.KeyMod.CtrlCmd : monaco.KeyMod.Alt;
editor.onKeyDown((e: MonacoTypes.IKeyboardEvent) => { editor.onKeyDown((e: MonacoTypes.IKeyboardEvent) => {
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(e.browserEvent); const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(e.browserEvent);
const handled = tryReinjectKey(waveEvent); const handled = tryReinjectKey(waveEvent);
@ -744,7 +742,6 @@ function CodeEditPreview({ parentRef, model }: SpecializedViewProps) {
return ( return (
<CodeEditor <CodeEditor
parentRef={parentRef}
text={fileContent} text={fileContent}
filename={fileName} filename={fileName}
onChange={(text) => setNewFileContent(text)} onChange={(text) => setNewFileContent(text)}