Skip to content

Commit 348fd67

Browse files
committed
更新monaco@0.37.1,修复多编辑器快捷键冲突,修复npm run dev
更新monaco@0.37.1(为后续优化ESLint做基础) 修复多编辑器快捷键冲突(0.31.0原本就有的多编辑器冲突未修复) 修复npm run dev
1 parent e65ee06 commit 348fd67

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"test": "jest --coverage",
99
"lint": "eslint --ext .js,.ts,.tsx src/",
10-
"dev": "concurrently \"webpack --mode development --config ./webpack/webpack.dev.ts\" \"npm run dev:linter\"",
10+
"dev": "webpack --mode development --config ./webpack/webpack.dev.ts",
1111
"build": "webpack --mode production --config ./webpack/webpack.prod.ts && concurrently \"npm run build:linter\" \"npm run build:no-split\"",
1212
"build:linter": "webpack --mode production --config ./webpack/webpack.linter.ts",
1313
"build:no-split": "webpack --mode production --config ./webpack/webpack.no.split.ts",
@@ -28,7 +28,7 @@
2828
"dayjs": "^1.11.4",
2929
"dexie": "^3.2.2",
3030
"jszip": "^3.10.1",
31-
"monaco-editor": "^0.31.0",
31+
"monaco-editor": "^0.37.1",
3232
"monaco-vim": "^0.3.4",
3333
"pako": "^2.0.4",
3434
"react": "^18.2.0",

src/pages/options/routes/script/ScriptEditor.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import ScriptResource from "@App/pages/components/ScriptResource";
3232
const { Row } = Grid;
3333
const { Col } = Grid;
3434

35+
// 声明一个Map存储Script
36+
const ScriptMap = new Map();
37+
3538
type HotKey = {
3639
hotKey: number;
3740
action: (script: Script, codeEditor: editor.IStandaloneCodeEditor) => void;
@@ -46,17 +49,34 @@ const Editor: React.FC<{
4649
}> = ({ id, script, hotKeys, callbackEditor, onChange }) => {
4750
const [init, setInit] = useState(false);
4851
const codeEditor = useRef<{ editor: editor.IStandaloneCodeEditor }>(null);
49-
52+
// Script.uuid为key,Script为value,储存Script
53+
ScriptMap.has(script.uuid) || ScriptMap.set(script.uuid, script);
5054
useEffect(() => {
5155
if (!codeEditor.current || !codeEditor.current.editor) {
5256
setTimeout(() => {
5357
setInit(true);
5458
}, 200);
5559
return () => {};
5660
}
61+
// 初始化editor时将Script的uuid绑定到editor上
62+
// @ts-ignore
63+
if (!codeEditor.current.editor.uuid) {
64+
// @ts-ignore
65+
codeEditor.current.editor.uuid = script.uuid;
66+
}
5767
hotKeys.forEach((item) => {
5868
codeEditor.current?.editor.addCommand(item.hotKey, () => {
59-
item.action(script, codeEditor.current!.editor);
69+
// 获取当前激活的editor(通过editor._focusTracker._hasFocus判断editor激活状态 可能有更好的方法)
70+
const activeEditor = editor
71+
.getEditors()
72+
// @ts-ignore
73+
// eslint-disable-next-line no-underscore-dangle
74+
.find((i) => i._focusTracker._hasFocus);
75+
76+
// 仅在获取到激活的editor时,通过editor上绑定的uuid获取Script,并指定激活的editor执行快捷键action
77+
activeEditor &&
78+
// @ts-ignore
79+
item.action(ScriptMap.get(activeEditor.uuid), activeEditor);
6080
});
6181
});
6282
codeEditor.current.editor.onKeyUp(() => {

webpack/webpack.dev.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import merge from "webpack-merge";
33
import CompressionPlugin from "compression-webpack-plugin";
44
import common from "../webpack.config";
55

6+
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
7+
68
const src = `${__dirname}/../src`;
79
const dist = `${__dirname}/../dist`;
810

@@ -13,6 +15,7 @@ common.entry = {
1315
inject: `${src}/inject.ts`,
1416
"editor.worker": "monaco-editor/esm/vs/editor/editor.worker.js",
1517
"ts.worker": "monaco-editor/esm/vs/language/typescript/ts.worker.js",
18+
"linter.worker": `${src}/linter.worker.ts`,
1619
};
1720

1821
common.output = {
@@ -33,5 +36,9 @@ export default merge(common, {
3336
test: /ts.worker.js/,
3437
deleteOriginalAssets: true,
3538
}),
39+
new NodePolyfillPlugin(),
3640
],
41+
resolve: {
42+
mainFields: ["browser", "main", "module"],
43+
},
3744
});

0 commit comments

Comments
 (0)