Fix new/reset button

This commit is contained in:
Luck
2023-01-08 20:33:17 +00:00
parent 042bace2c6
commit af1ba9c2b4
4 changed files with 38 additions and 20 deletions

View File

@@ -5,11 +5,18 @@ import Editor, {
OnMount,
} from '@monaco-editor/react';
import history from 'history/browser';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, {
MutableRefObject,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import styled from 'styled-components';
import themes, { makeMonacoTheme, Theme } from '../style/themes';
import type { editor } from 'monaco-editor';
import { ResetFunction } from './Editor';
export interface EditorTextAreaProps {
forcedContent: string;
@@ -19,6 +26,7 @@ export interface EditorTextAreaProps {
language: string;
fontSize: number;
readOnly: boolean;
resetFunction: MutableRefObject<ResetFunction | undefined>;
}
export default function EditorTextArea({
@@ -29,6 +37,7 @@ export default function EditorTextArea({
language,
fontSize,
readOnly,
resetFunction,
}: EditorTextAreaProps) {
const [editor, setEditor] = useState<editor.IStandaloneCodeEditor>();
const [monaco, setMonaco] = useState<Monaco>();
@@ -78,6 +87,11 @@ export default function EditorTextArea({
setEditor(editor);
setMonaco(monaco);
resetFunction.current = () => {
editor.setValue('');
editor.focus();
};
editor.focus();
};