From d91cff31a341d6ecd667396e530ae58502f64499 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 24 Mar 2020 18:02:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20editor=20=E7=BB=84=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20statuschange=20=E4=BA=8B=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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/view/components/editor/index.vue b/src/core/view/components/editor/index.vue index 0dfe3f9ea..b7d30b2b9 100644 --- a/src/core/view/components/editor/index.vue +++ b/src/core/view/components/editor/index.vue @@ -188,6 +188,7 @@ export default { default: break } + this.updateStatus(range) } else { errMsg = 'not ready' } @@ -231,7 +232,7 @@ export default { toolbar: false, readOnly: this.readOnly, placeholder: this.placeholder, - modules: { } + modules: {} } if (imageResizeModules.length) { Quill.register('modules/ImageResize', window.ImageResize.default) @@ -254,6 +255,11 @@ export default { quill.on(Quill.events.TEXT_CHANGE, () => { this.$trigger('input', {}, this.getContents()) }) + quill.on(Quill.events.SELECTION_CHANGE, this.updateStatus.bind(this)) + quill.on(Quill.events.SCROLL_OPTIMIZE, () => { + const range = quill.selection.getRange()[0] + this.updateStatus(range) + }) quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => { if (this.skipMatcher) { return delta @@ -307,6 +313,14 @@ export default { const delta = this.quill.clipboard.convert(content) this.skipMatcher = false return delta + }, + updateStatus (range) { + const status = range ? this.quill.getFormat(range) : {} + const keys = Object.keys(status) + if (keys.length !== Object.keys(this.__status || {}).length || keys.find(key => status[key] !== this.__status[key])) { + this.__status = status + this.$trigger('statuschange', {}, status) + } } } } -- GitLab