fix: 输入框 Enter 键忽略 IME 输入法合字阶段,防止误触提交
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m25s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m25s
中文输入法在选字时按回车,会触发 keydown.enter 事件, 但此时 v-model 尚未更新(组合阶段未结束),导致 inputValue 仍为空字符串,造成 saveToDiary 的 if (!name) return 分支被触发,配方从未保存,「我的配方」中自然看不到。 修复方案: - 监听 compositionstart / compositionend 事件, 用 isComposing 标记组合状态 - compositionend 时手动同步 inputValue(确保值最新) - submitPrompt 检查 e.isComposing || isComposing.value, 任一为真则跳过提交,等用户真正按下独立 Enter 再确认 Co-Authored-By: YoYo <yoyo@euphon.net>
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
type="text"
|
||||
style="width:100%;padding:10px 14px;border:1.5px solid #d4cfc7;border-radius:10px;font-size:14px;margin-bottom:16px;outline:none;font-family:inherit;box-sizing:border-box"
|
||||
@keydown.enter="submitPrompt"
|
||||
@compositionstart="isComposing = true"
|
||||
@compositionend="onCompositionEnd"
|
||||
ref="promptInput"
|
||||
/>
|
||||
<div class="dialog-btn-row">
|
||||
@@ -19,11 +21,12 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, nextTick } from 'vue'
|
||||
import { ref, watch, nextTick, shallowRef } from 'vue'
|
||||
import { dialogState, closeDialog } from '../composables/useDialog'
|
||||
|
||||
const inputValue = ref('')
|
||||
const promptInput = ref(null)
|
||||
const isComposing = shallowRef(false)
|
||||
|
||||
watch(() => dialogState.visible, (v) => {
|
||||
if (v && dialogState.type === 'prompt') {
|
||||
@@ -46,7 +49,15 @@ function cancel() {
|
||||
else closeDialog(null)
|
||||
}
|
||||
|
||||
function submitPrompt() {
|
||||
function onCompositionEnd(e) {
|
||||
isComposing.value = false
|
||||
// After compositionend, update the model value with the committed text
|
||||
inputValue.value = e.target.value
|
||||
}
|
||||
|
||||
function submitPrompt(e) {
|
||||
// Ignore Enter during IME composition (e.g. Chinese input method confirming a character)
|
||||
if (e.isComposing || isComposing.value) return
|
||||
closeDialog(inputValue.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user