Skip to content

Commit

Permalink
fix: 扩展未加载完成对编辑器进行部分操作报错(#84
Browse files Browse the repository at this point in the history
  • Loading branch information
imzbf committed Apr 24, 2022
1 parent efb4a9b commit 8437b1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
5 changes: 5 additions & 0 deletions MdEditor/layouts/Modals/Clip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export default defineComponent({

// 直接定义onchange,防止创建新的实例时遗留事件
(uploadRef.value as HTMLInputElement).onchange = () => {
if (!Cropper) {
// CATCH ERROR: 捕获全局错误
return;
}

const fileList = (uploadRef.value as HTMLInputElement).files || [];

// 切换模式
Expand Down
29 changes: 16 additions & 13 deletions MdEditor/layouts/Toolbar/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export const useSreenfull = (props: any) => {
// 是否组件内部全屏标识
const screenfullMe = ref(false);

// 触发器
const fullScreenHandler = () => {
if (!screenfull) {
// CATCH ERROR: 捕获全局错误
return;
}

if (screenfull.isEnabled) {
screenfullMe.value = true;
if (screenfull.isFullscreen) {
Expand All @@ -22,11 +28,8 @@ export const useSreenfull = (props: any) => {
}
};

const screenfullLoad = () => {
// 复制实例
screenfull = window.screenfull;

// 注册事件
// 挂载监听事件
const onScreenfullEvent = () => {
if (screenfull && screenfull.isEnabled) {
screenfull.on('change', () => {
if (screenfullMe.value) {
Expand All @@ -37,15 +40,15 @@ export const useSreenfull = (props: any) => {
}
};

const screenfullLoad = () => {
// 复制实例
screenfull = window.screenfull;
// 重新监听
onScreenfullEvent();
};

onMounted(() => {
if (screenfull && screenfull.isEnabled) {
screenfull.on('change', () => {
if (screenfullMe.value) {
screenfullMe.value = false;
props.updateSetting(!props.setting.fullscreen, 'fullscreen');
}
});
}
onScreenfullEvent();

if (!previewOnly && props.screenfull === null) {
const screenScript = document.createElement('script');
Expand Down
5 changes: 5 additions & 0 deletions MdEditor/utils/content-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export const directive2flag = (
targetValue = `${pix} ${selectedText}`;
deviationStart = pix.length + 1;
} else if (direct === 'prettier') {
if (!window.prettier) {
// CATCH ERROR: 捕获全局错误
return inputArea.value;
}

return window.prettier.format(inputArea.value, {
parser: 'markdown',
plugins: window.prettierPlugins
Expand Down

0 comments on commit 8437b1b

Please sign in to comment.