refactor(仪表板): 富文本视图富文本组件进入编辑状态自动聚焦在文档末尾

This commit is contained in:
wangjiahao 2024-01-18 13:43:17 +08:00
parent 378237557a
commit 6cd15f6e9b
2 changed files with 40 additions and 0 deletions

View File

@ -164,7 +164,27 @@ export default {
this.editShow = false this.editShow = false
this.$nextTick(() => { this.$nextTick(() => {
this.editShow = true this.editShow = true
this.editCursor()
}) })
},
editCursor() {
setTimeout(() => {
const myDiv = document.getElementById(this.tinymceId)
//
const range = document.createRange()
const sel = window.getSelection()
if (myDiv.childNodes) {
range.setStart(myDiv.childNodes[myDiv.childNodes.length - 1], 1)
range.collapse(false)
sel.removeAllRanges()
sel.addRange(range)
}
//
if (myDiv.focus) {
myDiv.focus()
}
}, 100)
} }
} }
} }

View File

@ -239,8 +239,28 @@ export default {
this.editShow = false this.editShow = false
this.$nextTick(() => { this.$nextTick(() => {
this.editShow = true this.editShow = true
this.editCursor()
}) })
}, },
editCursor() {
setTimeout(() => {
const myDiv = document.getElementById(this.tinymceId)
//
const range = document.createRange()
const sel = window.getSelection()
if (myDiv.childNodes) {
range.setStart(myDiv.childNodes[myDiv.childNodes.length - 1], 1)
range.collapse(false)
sel.removeAllRanges()
sel.addRange(range)
}
//
if (myDiv.focus) {
myDiv.focus()
}
}, 100)
},
chartResize() { chartResize() {
// ignore // ignore
} }