From 58c978ae3af6fd3262b7f9807b1a9fef77a6c1f6 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 9 Jun 2021 17:55:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=BF=AE=E5=A4=8D=20=20insertIm?= =?UTF-8?q?age=20=E5=A4=9A=E6=AC=A1=E8=A7=A6=E5=8F=91=20input=20=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/editor/index.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/view/components/editor/index.vue b/src/core/view/components/editor/index.vue index 44c568fd1..977901bbd 100644 --- a/src/core/view/components/editor/index.vue +++ b/src/core/view/components/editor/index.vue @@ -16,6 +16,7 @@ import HTMLParser from 'uni-helpers/html-parser' import * as formats from './formats' import loadScript from './load-script' +let textChanging = false export default { name: 'Editor', mixins: [subscriber, emitter, keyboard], @@ -149,11 +150,14 @@ export default { const path = this.$getRealPath(src) quill.insertEmbed(range.index, 'image', path, Quill.sources.USER) const local = /^(file|blob):/.test(path) ? path : false + // 防止 formatText 多次触发 Quill.events.TEXT_CHANGE 事件 + textChanging = true quill.formatText(range.index, 1, 'data-local', local) quill.formatText(range.index, 1, 'alt', alt) quill.formatText(range.index, 1, 'width', width) quill.formatText(range.index, 1, 'height', height) quill.formatText(range.index, 1, 'class', extClass) + textChanging = false quill.formatText(range.index, 1, 'data-custom', Object.keys(data).map(key => `${key}=${data[key]}`).join('&')) quill.setSelection(range.index + 1, Quill.sources.SILENT) } @@ -262,7 +266,9 @@ export default { }) }) quill.on(Quill.events.TEXT_CHANGE, () => { - this.$trigger('input', {}, this.getContents()) + if (!textChanging) { + this.$trigger('input', {}, this.getContents()) + } }) quill.on(Quill.events.SELECTION_CHANGE, this.updateStatus.bind(this)) quill.on(Quill.events.SCROLL_OPTIMIZE, () => { -- GitLab