提交 4784813e 编写于 作者: L liuxiaohang

fix: editor insertImage 触发 input 方法没有 alt 属性 question/155163

上级 f8e5823f
...@@ -29,7 +29,6 @@ function isiOS () { ...@@ -29,7 +29,6 @@ function isiOS () {
return false return false
} }
let textChanging = false
export default { export default {
name: 'Editor', name: 'Editor',
mixins: [subscriber, emitter, keyboard], mixins: [subscriber, emitter, keyboard],
...@@ -106,6 +105,9 @@ export default { ...@@ -106,6 +105,9 @@ export default {
}) })
}, },
methods: { methods: {
_textChangeHandler () {
this.$trigger('input', {}, this.getContents())
},
_handleSubscribe ({ _handleSubscribe ({
type, type,
data data
...@@ -161,18 +163,19 @@ export default { ...@@ -161,18 +163,19 @@ export default {
range = quill.getSelection(true) range = quill.getSelection(true)
const { src = '', alt = '', width = '', height = '', extClass = '', data = {} } = options const { src = '', alt = '', width = '', height = '', extClass = '', data = {} } = options
const path = this.$getRealPath(src) const path = this.$getRealPath(src)
quill.insertEmbed(range.index, 'image', path, Quill.sources.USER) quill.insertEmbed(range.index, 'image', path, Quill.sources.SILENT)
const local = /^(file|blob):/.test(path) ? path : false const local = /^(file|blob):/.test(path) ? path : false
// 防止 formatText 多次触发 Quill.events.TEXT_CHANGE 事件 quill.formatText(range.index, 1, 'data-local', local, Quill.sources.SILENT)
textChanging = true quill.formatText(range.index, 1, 'alt', alt, Quill.sources.SILENT)
quill.formatText(range.index, 1, 'data-local', local) quill.formatText(range.index, 1, 'width', width, Quill.sources.SILENT)
quill.formatText(range.index, 1, 'alt', alt) quill.formatText(range.index, 1, 'height', height, Quill.sources.SILENT)
quill.formatText(range.index, 1, 'width', width) quill.formatText(range.index, 1, 'class', extClass, Quill.sources.SILENT)
quill.formatText(range.index, 1, 'height', height) quill.formatText(range.index, 1, 'data-custom', Object.keys(data).map(key => `${key}=${data[key]}`).join('&'), Quill.sources.SILENT)
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) quill.setSelection(range.index + 1, Quill.sources.SILENT)
quill.scrollIntoView()
setTimeout(() => {
this._textChangeHandler()
}, 1000)
} }
break break
case 'insertText': case 'insertText':
...@@ -289,11 +292,7 @@ export default { ...@@ -289,11 +292,7 @@ export default {
} }
}) })
}) })
quill.on(Quill.events.TEXT_CHANGE, () => { quill.on(Quill.events.TEXT_CHANGE, this._textChangeHandler)
if (!textChanging) {
this.$trigger('input', {}, this.getContents())
}
})
quill.on(Quill.events.SELECTION_CHANGE, this.updateStatus.bind(this)) quill.on(Quill.events.SELECTION_CHANGE, this.updateStatus.bind(this))
quill.on(Quill.events.SCROLL_OPTIMIZE, () => { quill.on(Quill.events.SCROLL_OPTIMIZE, () => {
const range = quill.selection.getRange()[0] const range = quill.selection.getRange()[0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册