mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 00:11:08 +08:00
fix(editor): update editorRef initialization and handleChange logic for better type safety #5442
This commit is contained in:
parent
d0d35da2f1
commit
9c24b3089c
@ -103,7 +103,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
[initialData],
|
||||
);
|
||||
|
||||
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
|
||||
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(undefined);
|
||||
const prevData = useRef<string | undefined>("");
|
||||
const currData = useRef<string | undefined>("");
|
||||
|
||||
@ -126,8 +126,9 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleChange = useLockFn(async (value: string | undefined) => {
|
||||
const handleChange = useLockFn(async (_value?: string) => {
|
||||
try {
|
||||
const value = editorRef.current?.getValue();
|
||||
currData.current = value;
|
||||
onChange?.(prevData.current, currData.current);
|
||||
} catch (err) {
|
||||
@ -138,6 +139,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
if (!readOnly) {
|
||||
currData.current = editorRef.current?.getValue();
|
||||
onSave?.(prevData.current, currData.current);
|
||||
}
|
||||
onClose();
|
||||
@ -175,12 +177,12 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
return () => {
|
||||
unlistenResized.then((fn) => fn());
|
||||
editorRef.current?.dispose();
|
||||
editorRef.current = null;
|
||||
editorRef.current = undefined;
|
||||
};
|
||||
}, [editorResize]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={handleClose} maxWidth="xl" fullWidth>
|
||||
<Dialog open={open} onClose={onClose} maxWidth="xl" fullWidth>
|
||||
<DialogTitle>{resolvedTitle}</DialogTitle>
|
||||
|
||||
<DialogContent
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user