From 21e21eedf3b08cfa0dc2788ca6ff0caf25b35b7f Mon Sep 17 00:00:00 2001 From: JimQing Date: Sun, 3 May 2020 11:02:27 +0800 Subject: [PATCH] fix: code prettify --- src/components/CodemirrorEditor.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/CodemirrorEditor.vue b/src/components/CodemirrorEditor.vue index 4fafcd0..66e6de4 100644 --- a/src/components/CodemirrorEditor.vue +++ b/src/components/CodemirrorEditor.vue @@ -77,6 +77,7 @@ export default { aboutDialogVisible: false, dialogFormVisible: false, timeout: null, + changeTimer: null, source: '' } }, @@ -106,11 +107,13 @@ export default { initEditor() { this.initEditorEntity(); this.editor.on('change', (cm, e) => { - this.editorRefresh() - setTimeout(() => { - PR.prettyPrint() + if (this.changeTimer) clearTimeout(this.changeTimer); + this.changeTimer = setTimeout(() => { + setTimeout(()=> PR.prettyPrint(), 0); + this.editorRefresh() + console.log('tick'); + saveEditorContent(this.editor, '__editor_content') }, 300); - saveEditorContent(this.editor, '__editor_content') }); // 粘贴上传图片并插入