From b90d9ff59b630c27614ee11dc3c1c6299a7a9024 Mon Sep 17 00:00:00 2001 From: JimQing Date: Sat, 4 Jul 2020 00:55:40 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/codeMirror/header.vue | 31 +++++++++++++++------------- src/scripts/util.js | 10 +++++++++ src/view/CodemirrorEditor.vue | 11 ---------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/components/codeMirror/header.vue b/src/components/codeMirror/header.vue index 0d73896..bc85a9f 100644 --- a/src/components/codeMirror/header.vue +++ b/src/components/codeMirror/header.vue @@ -73,7 +73,8 @@ import { setColorWithCustomTemplate, setFontSize, - isImageIllegal + isImageIllegal, + fixCodeWhiteSpace } from '../../scripts/util' import fileApi from '../../api/file'; import { @@ -173,20 +174,22 @@ export default { copy() { this.$emit('startCopy'); setTimeout(() => { - solveWeChatImage() - this.setOutput(solveHtml()) - let clipboardDiv = document.getElementById('output') + solveWeChatImage(); + fixCodeWhiteSpace(); + this.setOutput(solveHtml()); + let clipboardDiv = document.getElementById('output'); - clipboardDiv.focus() - window.getSelection().removeAllRanges() - let range = document.createRange() + clipboardDiv.focus(); + window.getSelection().removeAllRanges(); + let range = document.createRange(); - range.setStartBefore(clipboardDiv.firstChild) - range.setEndAfter(clipboardDiv.lastChild) - window.getSelection().addRange(range) - document.execCommand('copy') - range.setStartBefore(clipboardDiv.firstChild) - range.setEndAfter(clipboardDiv.firstChild) + range.setStartBefore(clipboardDiv.firstChild); + range.setEndAfter(clipboardDiv.lastChild); + window.getSelection().addRange(range); + document.execCommand('copy'); + range.setStartBefore(clipboardDiv.firstChild); + range.setEndAfter(clipboardDiv.firstChild); + fixCodeWhiteSpace('normal'); // 输出提示 this.$notify({ showClose: true, @@ -194,7 +197,7 @@ export default { offset: 80, duration: 1600, type: 'success' - }) + }); this.$emit('refresh'); this.$emit('endCopy'); }, 350); diff --git a/src/scripts/util.js b/src/scripts/util.js index aa48894..c70174e 100644 --- a/src/scripts/util.js +++ b/src/scripts/util.js @@ -204,3 +204,13 @@ export function formatDoc(content) { }) return doc } + +export function fixCodeWhiteSpace(value = 'pre') { + const preDomList = document.getElementsByClassName('code__pre'); + + if (preDomList.length > 0) { + preDomList.forEach(pre=> { + pre.style.whiteSpace = value; + }) + } +} \ No newline at end of file diff --git a/src/view/CodemirrorEditor.vue b/src/view/CodemirrorEditor.vue index e77475e..296a0ea 100644 --- a/src/view/CodemirrorEditor.vue +++ b/src/view/CodemirrorEditor.vue @@ -236,17 +236,6 @@ export default { }, mounted() { this.leftAndRightScroll() - }, - watch: { - isCoping(newVal) { - const preDomList = document.getElementsByClassName('code__pre'); - - if (preDomList.length > 0) { - preDomList.forEach(pre=> { - pre.style.whiteSpace = newVal ? 'pre' : 'normal'; - }) - } - } } }