Skip to content

Commit 4b8dae1

Browse files
authored
🐛 修正AppContext错误引用"monaco-editor" (#983)
1 parent 493b31d commit 4b8dae1

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/pages/components/CodeEditor/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { editor, Range } from "monaco-editor";
22
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
33
import { globalCache, systemConfig } from "@App/pages/store/global";
44
import { LinterWorker } from "@App/pkg/utils/monaco-editor";
5+
import { fnPlaceHolder } from "@App/pages/store/AppContext";
6+
7+
fnPlaceHolder.setEditorTheme = (theme: string) => editor.setTheme(theme);
58

69
type Props = {
710
className?: string;

src/pages/store/AppContext.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React, { useState, createContext, type ReactNode, useEffect, useContext } from "react";
22
import { messageQueue } from "./global";
3-
import { editor } from "monaco-editor";
43
import { type TKeyValue } from "@Packages/message/message_queue";
54
import { changeLanguage } from "@App/locales/locales";
65
import { SystemConfigChange } from "@App/pkg/config/config";
76

7+
export const fnPlaceHolder = {
8+
setEditorTheme: null,
9+
} as { setEditorTheme: ((theme: string) => void) | null };
10+
811
export type ThemeParam = { theme: "auto" | "light" | "dark" };
912
export interface AppContextType {
1013
colorThemeState: "auto" | "light" | "dark";
@@ -49,12 +52,12 @@ const setAppColorTheme = (theme: "light" | "dark" | "auto") => {
4952
case "dark":
5053
document.documentElement.classList.add("dark");
5154
document.body.setAttribute("arco-theme", "dark");
52-
editor.setTheme("vs-dark");
55+
fnPlaceHolder.setEditorTheme?.("vs-dark");
5356
break;
5457
case "light":
5558
document.documentElement.classList.remove("dark");
5659
document.body.removeAttribute("arco-theme");
57-
editor.setTheme("vs");
60+
fnPlaceHolder.setEditorTheme?.("vs");
5861
break;
5962
}
6063
};

0 commit comments

Comments
 (0)