From ead2676f0b0721c4e965f126af09f3a0e1483212 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Sun, 6 Jul 2025 23:10:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E5=85=89=E6=A0=87=E7=A7=BB=E4=BD=8D=E9=80=80?= =?UTF-8?q?=E6=A0=BC=E6=9A=B4=E9=9C=B2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/FTInput/index.vue | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/common/FTInput/index.vue b/src/components/common/FTInput/index.vue index b4e43f2..fbe6b3a 100644 --- a/src/components/common/FTInput/index.vue +++ b/src/components/common/FTInput/index.vue @@ -180,12 +180,18 @@ const ignoreBlur = ref(false) const handleBackspace = () => { ignoreBlur.value = true - // const position = keyboard.value.getCaretPosition() - // console.log(position) - const value = model.value?.toString() || '' - model.value = value.slice(0, -1) + const input = model.value?.toString() || '' + let index: number | null - console.log(model.value) + // 有选中文本时删除整个选区 + const start = keyboard.value.getCaretPosition() + const end = keyboard.value.getCaretPositionEnd() + model.value = input.slice(0, start) + input.slice(end) + // eslint-disable-next-line prefer-const + index = start + + // 更新光标位置 + keyboard.value.setCaretPosition(index) // 设置短时间延迟恢复 blur 监听 setTimeout(() => { ignoreBlur.value = false