Skip to content

Commit d33111e

Browse files
authored
Add files via upload
1 parent 7c3b1eb commit d33111e

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

3code_mobile.html

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
}
275275

276276
.keyboard-key.highlighted {
277+
/* 用於 touchstart/mousedown 設置的高亮狀態 */
277278
background-color: var(--key-active-bg) !important;
278279
color: white;
279280
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
@@ -313,6 +314,7 @@
313314
}
314315

315316
.keyboard-key:active {
317+
/* 作為降級/輔助的點擊視覺效果,但在 touchstart 設置 highlighted 後會被覆蓋 */
316318
background-color: var(--key-active-bg);
317319
color: white;
318320
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
@@ -381,7 +383,8 @@
381383
// --- 長按相關狀態 ---
382384
let longPressTimer = null;
383385
let longPressCommitted = false;
384-
const LONG_PRESS_TIMEOUT = 500;
386+
// *** 修正點 2:延長長按時限,更容易觸發 ***
387+
const LONG_PRESS_TIMEOUT = 750; // 500ms -> 750ms
385388

386389
// --- 游標 HTML 定義 ---
387390
const CURSOR_HTML = '<span id="main-cursor" class="cursor">\u200c</span>';
@@ -414,7 +417,7 @@
414417
const KEYCODE_ENTER=0x0d;
415418
const KEYCODE_SPACE=0x20;
416419

417-
// --- 鍵盤配置 ---
420+
// --- 鍵盤配置 (略) ---
418421
var Keyboards = {
419422
english: {
420423
shifted : false,
@@ -510,7 +513,7 @@
510513
}
511514

512515
/**
513-
* 鍵盤渲染函數
516+
* 鍵盤渲染函數 (略)
514517
*/
515518
function drawKeyboard() {
516519
const layout = currentLayout;
@@ -673,7 +676,7 @@
673676
}
674677

675678
/**
676-
* 浮層處理函數 (保持不變)
679+
* 浮層處理函數 ()
677680
*/
678681
function emoji(subIndex) {
679682
const emojis=[[
@@ -736,7 +739,7 @@
736739
}
737740

738741
/**
739-
* 處理短按事件:執行編碼或普通字符輸入
742+
* 處理短按事件:執行編碼或普通字符輸入 (略)
740743
*/
741744
function handleShortPress(keyElement) {
742745
preferredOffset = -1;
@@ -781,7 +784,7 @@
781784
}
782785

783786
/**
784-
* 處理功能鍵邏輯
787+
* 處理功能鍵邏輯 (略)
785788
*/
786789
function handleFunctionKey(code, keyChar) {
787790
switch(code) {
@@ -869,7 +872,6 @@
869872

870873
/**
871874
* 統一的事件綁定函數 (同時支援 Touch 和 Mouse)
872-
* 【修正區域:優化反白邏輯,移除導致無法點擊的檢查】
873875
*/
874876
function bindKeyEvents() {
875877
document.querySelectorAll('.keyboard-key').forEach(keyElement => {
@@ -879,13 +881,13 @@
879881
keyElement.removeEventListener('touchstart', keyElement.handlePressDown);
880882
keyElement.removeEventListener('touchend', keyElement.handlePressUp);
881883
keyElement.removeEventListener('touchmove', keyElement.handlePressCancel);
882-
keyElement.removeEventListener('touchcancel', keyElement.handlePressCancel); // 新增:確保移除 touchcancel
884+
keyElement.removeEventListener('touchcancel', keyElement.handlePressCancel);
883885
keyElement.removeEventListener('mousedown', keyElement.handlePressDown);
884886
keyElement.removeEventListener('mouseup', keyElement.handlePressUp);
885887
keyElement.removeEventListener('mouseleave', keyElement.handlePressCancel);
886888
}
887889

888-
// 清空舊的 onxxx 屬性
890+
// 清空舊的 onxxx 屬性 (略)
889891
keyElement.onclick = null;
890892
keyElement.oncontextmenu = (e) => e.preventDefault();
891893
keyElement.ontouchstart = null;
@@ -918,16 +920,14 @@
918920

919921
// 2. 處理抬起/點擊 (Press Up)
920922
const handlePressUp = (event) => {
921-
// 移除 touchend 上的 preventDefault
922-
// if (event.type.startsWith('touch')) event.preventDefault();
923-
923+
// if (event.type.startsWith('touch')) event.preventDefault(); // 移除 preventDefault
924+
924925
if (longPressTimer) {
925926
clearTimeout(longPressTimer);
926927
longPressTimer = null;
927928
}
928929

929-
// *** 修正:只要不是長按提交的,就視為短按並觸發輸入。***
930-
// 以前的邏輯會檢查 'highlighted' 類別,但 touchmove 會移除它,導致輕微移動就無法輸入。
930+
// 只要不是長按提交的,就視為短按並觸發輸入
931931
if (!longPressCommitted) {
932932
handleShortPress(keyElement);
933933
}
@@ -938,14 +938,17 @@
938938
};
939939

940940
// 3. 處理取消 (Move/Leave/Cancel)
941-
const handlePressCancel = () => {
941+
const handlePressCancel = (event) => { // 接受 event
942942
if (longPressTimer) {
943943
clearTimeout(longPressTimer);
944944
longPressTimer = null;
945945
}
946-
// 移動、離開或觸摸中斷時立即移除高亮
947-
keyElement.classList.remove('highlighted');
948-
// 讓 longPressCommitted 保持原狀 (true 或 false),它在 handlePressUp 中決定是否執行 short press
946+
// *** 修正點 1:輕微的 touchmove 不再移除高亮,避免瞬間反白消失。***
947+
// 只有在滑鼠離開 (mouseleave) 或系統明確取消 (touchcancel) 時,才移除高亮。
948+
// 正常的 touchend/mouseup 會在 handlePressUp 中移除高亮。
949+
if (event.type === 'mouseleave' || event.type === 'touchcancel') {
950+
keyElement.classList.remove('highlighted');
951+
}
949952
};
950953

951954
// 將函數儲存在 DOM 元素上以便移除
@@ -957,8 +960,8 @@
957960
keyElement.addEventListener('touchstart', handlePressDown);
958961
keyElement.addEventListener('touchend', handlePressUp);
959962
keyElement.addEventListener('touchcancel', handlePressCancel); // 處理觸摸中斷
960-
keyElement.addEventListener('touchmove', handlePressCancel); // 處理手指移動取消 (主要用於取消長按,但也會導致輕微移動無法反白,這是我們接受的視覺取捨)
961-
963+
keyElement.addEventListener('touchmove', handlePressCancel); // 處理手指移動取消長按計時器
964+
962965
// Mouse Events (用於桌面測試)
963966
keyElement.addEventListener('mousedown', handlePressDown);
964967
keyElement.addEventListener('mouseup', handlePressUp);
@@ -967,7 +970,7 @@
967970
}
968971

969972
/**
970-
* 處理單字符輸入 (用於英文/符號模式或 Shift+字母)
973+
* 處理單字符輸入 (用於英文/符號模式或 Shift+字母) (略)
971974
*/
972975
function handleCharInput(char) {
973976
if (currentLayout.shifted) {
@@ -982,7 +985,7 @@
982985
}
983986
}
984987

985-
// --- 核心輸入法邏輯 (其餘部分保持不變) ---
988+
// --- 核心輸入法邏輯 (其餘部分略) ---
986989

987990
var currentCode = '';
988991
var currentCandidates = [];
@@ -1244,7 +1247,7 @@
12441247
updateOutputDisplay();
12451248
}
12461249

1247-
// --- 工具列與查碼功能 (其餘部分保持不變) ---
1250+
// --- 工具列與查碼功能 (其餘部分略) ---
12481251

12491252
function copyTextToClipboard() {
12501253
const textToCopy = committedText;

0 commit comments

Comments
 (0)