From 34b975f657fedecc152b5707d5ca2d334f544f29 Mon Sep 17 00:00:00 2001 From: obgnail Date: Tue, 15 Aug 2023 17:59:25 +0800 Subject: [PATCH] =?UTF-8?q?hotfix:=20=E5=85=BC=E5=AE=B9=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/auto_number.js | 17 +++++++++++++++-- plugin/global/utils.js | 4 ++-- plugin/read_only.js | 2 +- plugin/test.js | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/plugin/auto_number.js b/plugin/auto_number.js index 7fbd6561..d5d213ad 100644 --- a/plugin/auto_number.js +++ b/plugin/auto_number.js @@ -261,8 +261,21 @@ } } - global._pluginUtils.decorate(() => !!File, File.editor.export, "exportToHTML", decoMixin.beforeExport, null); - global._pluginUtils.decorate(() => !!File, File.editor.library.outline, "getHeaderMatrix", null, decoMixin.afterGetHeaderMatrix); + global._pluginUtils.decorate( + () => (File && File.editor && File.editor.export && File.editor.export.exportToHTML), + File.editor.export, + "exportToHTML", + decoMixin.beforeExport, + null + ); + global._pluginUtils.decorate( + () => (File && File.editor && File.editor.library && File.editor.library.outline + && File.editor.library.outline.getHeaderMatrix), + File.editor.library.outline, + "getHeaderMatrix", + null, + decoMixin.afterGetHeaderMatrix + ); } //////////////////////// 以下是声明式插件系统代码 //////////////////////// diff --git a/plugin/global/utils.js b/plugin/global/utils.js index c1f70ec7..1f01e5d3 100644 --- a/plugin/global/utils.js +++ b/plugin/global/utils.js @@ -67,11 +67,11 @@ } const decorateOpenFile = (before, after) => { - decorate(() => !!File, File.editor.library, "openFile", before, after) + decorate(() => (File && File.editor && File.editor.library && File.editor.library.openFile), File.editor.library, "openFile", before, after) } const decorateAddCodeBlock = (before, after) => { - decorate(() => !!File, File.editor.fences, "addCodeBlock", before, after) + decorate(() => (File && File.editor && File.editor.fences && File.editor.fences.addCodeBlock), File.editor.fences, "addCodeBlock", before, after) } const loopDetector = (until, after, detectInterval = 20) => { diff --git a/plugin/read_only.js b/plugin/read_only.js index cf21e02d..1bcd2fef 100644 --- a/plugin/read_only.js +++ b/plugin/read_only.js @@ -63,7 +63,7 @@ global._pluginUtils.registerWindowHotkey(config.HOTKEY, call); global._pluginUtils.decorate( - () => !!File, + () => (File && File.freshLock), File, "freshLock", null, diff --git a/plugin/test.js b/plugin/test.js index ec058013..c3f47367 100644 --- a/plugin/test.js +++ b/plugin/test.js @@ -1,7 +1,7 @@ (() => { // 打开新窗口后自动关闭 global._pluginUtils.decorate( - () => !!File, + () => (File && File.editor && File.editor.library && File.editor.library.openFileInNewWindow), File.editor.library, "openFileInNewWindow", null,