Commit b79e5d0e by 胡悦

修改

1 parent 54654b73
......@@ -6,8 +6,8 @@
ref="wTextareaContent"
:id="contentId"
@click="inputClick($event)"
@focus="isLocked = true"
@blur="isLocked = false"
@focus="onFocus"
@blur="onBlur"
@keydown.delete="handleDelete($event)"
@input="handleInput($event.target)"
></div>
......@@ -41,6 +41,7 @@ export default {
contentId: `content${this.getGuid()}`,
// 输入的时候锁定,禁止更新innerHTML
isLocked: false,
isInsert: false,
// 记录当前选中tag的ID
currentTagId: null,
// 当前光标位置
......@@ -189,12 +190,34 @@ export default {
node.src = url
this.insertNode(node)
},
onFocus() {
this.isLocked = true
this.isInsert = true
},
onBlur() {
this.isLocked = false
},
insertNode(node) {
// 在内容中插入标签
// 删掉选中的内容(如有)
if (this.savedRange.startContainer) {
this.insertNodeFirst(node)
} else {
document.querySelector('.w-textarea_input').focus()
setTimeout(() => {
this.insertNodeFirst(node)
}, 100)
}
},
insertNodeFirst(node) {
this.savedRange.deleteContents()
// 插入链接
this.savedRange.insertNode(node)
if (this.isInsert) {
this.savedRange.insertNode(node)
} else {
document.querySelector('.w-textarea_input').appendChild(node)
}
this.isInsert = false
// 更新双向绑定数据
let target = this.$refs.wTextareaContent
if (navigator.userAgent.indexOf('Firefox') > 0 || navigator.userAgent.indexOf('QQBrowser') > 0) {
......@@ -458,7 +481,6 @@ export default {
let Textnode = document.createElement('div')
Textnode.innerHTML = replaceImg
this.currentText = Textnode.innerText
console.log(this.currentText, 11111111)
this.$emit('updateText', this.currentText)
},
handleDelete(e) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!