From 6506988f33029d1b83c5d11e0068b8d2924d5ebf Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 21 Apr 2026 09:30:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(mobile):=20=E4=BC=98=E5=8C=96=E8=A7=A6?= =?UTF-8?q?=E6=91=B8=E7=BC=96=E8=BE=91=E5=92=8C=E9=94=AE=E7=9B=98=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/script.js | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/js/script.js b/js/script.js index 7d96b31..74cb860 100644 --- a/js/script.js +++ b/js/script.js @@ -1057,26 +1057,18 @@ // 移动端:触摸结束后进入编辑(更灵敏) let lastTapTime = 0; - let touchEditTriggered = false; element.addEventListener('touchend', (e) => { // 如果正在拖拽,不触发编辑 if (isDragging) return; - // 防止 touchend 后立即触发 click 导致重复进入编辑 - e.preventDefault(); - e.stopPropagation(); - const currentTime = Date.now(); // 双击检测(300ms内两次点击) if (currentTime - lastTapTime < 300) { // 双击已在 click 事件中处理,这里不重复 - touchEditTriggered = true; } else { // 单击延迟处理,避免与拖拽冲突 - touchEditTriggered = false; setTimeout(() => { - if (!isDragging && !touchEditTriggered && editingInput !== element) { - touchEditTriggered = true; + if (!isDragging && editingInput !== element) { selectInput(element); startEdit(element); } @@ -1137,6 +1129,9 @@ // 更新工具栏状态 updateToolbarState(element); + // 立即 focus 以触发键盘(必须在用户交互的同步上下文中) + element.focus(); + // 如果没有选中文本,则定位光标到末尾 setTimeout(() => { const sel = window.getSelection(); @@ -1147,29 +1142,9 @@ sel.removeAllRanges(); sel.addRange(range); } - element.focus(); - - // 尝试多种方式触发键盘弹出 - // 方式1: 标准 focus - element.focus(); - - // 方式2: 对于 iOS,需要创建一个临时的 input 来触发键盘 - if (/iPad|iPhone|iPod/.test(navigator.userAgent)) { - const tempInput = document.createElement('input'); - tempInput.style.position = 'fixed'; - tempInput.style.opacity = '0'; - tempInput.style.top = '-1000px'; - document.body.appendChild(tempInput); - tempInput.focus(); - setTimeout(() => { - tempInput.blur(); - tempInput.remove(); - element.focus(); - }, 100); - } - }, 10); + }, 0); - // 方式3: 使用 Virtual Keyboard API(如果支持) + // 使用 Virtual Keyboard API(如果支持) if ('virtualKeyboard' in navigator) { navigator.virtualKeyboard.show(); }