diff --git a/core/frontend/src/components/canvas/customComponent/DeRichText.vue b/core/frontend/src/components/canvas/customComponent/DeRichText.vue index 4e5a76ab38..613b543495 100644 --- a/core/frontend/src/components/canvas/customComponent/DeRichText.vue +++ b/core/frontend/src/components/canvas/customComponent/DeRichText.vue @@ -164,7 +164,27 @@ export default { this.editShow = false this.$nextTick(() => { 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) } } } diff --git a/core/frontend/src/components/canvas/customComponent/DeRichTextView.vue b/core/frontend/src/components/canvas/customComponent/DeRichTextView.vue index 4ce160e6b6..78598a00e8 100644 --- a/core/frontend/src/components/canvas/customComponent/DeRichTextView.vue +++ b/core/frontend/src/components/canvas/customComponent/DeRichTextView.vue @@ -239,8 +239,28 @@ export default { this.editShow = false this.$nextTick(() => { 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() { // ignore }