From 6cd15f6e9b2d52adc8751d5ec1a860210ce41434 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Thu, 18 Jan 2024 13:43:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=AA=E8=A1=A8=E6=9D=BF):=20?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E8=A7=86=E5=9B=BE=E5=AF=8C=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E7=BB=84=E4=BB=B6=E8=BF=9B=E5=85=A5=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=87=AA=E5=8A=A8=E8=81=9A=E7=84=A6=E5=9C=A8?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=9C=AB=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canvas/customComponent/DeRichText.vue | 20 +++++++++++++++++++ .../canvas/customComponent/DeRichTextView.vue | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) 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 }