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