Skip to content

Commit 8475f4f

Browse files
authored
Add files via upload
1 parent 78b1c30 commit 8475f4f

1 file changed

Lines changed: 35 additions & 27 deletions

File tree

test.html

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ <h2>查碼練習</h2>
671671
} else {
672672
let char = keyname_map_lower[code];
673673
if (!char) {
674-
// Fallback for codes not in map
675674
char = code;
676675
}
677676

@@ -701,16 +700,26 @@ <h2>查碼練習</h2>
701700
deleteTextAtCursor(textOutput);
702701
}
703702
}
704-
}
705-
if (key === 'Enter' || key === 'enter') {
703+
} else if (key === 'Enter' || key === 'enter') {
706704
if (currentCandidates.length > 0) {
707705
selectCandidate(0);
708706
} else {
709707
insertTextAtCursor(textOutput, '\n');
710708
}
711-
}
712-
if (key === 'Escape' || key === 'escape') {
709+
} else if (key === 'Escape' || key === 'escape') {
713710
resetInputState();
711+
} else if (key === ' ' || key === 'Space') {
712+
if (isEnglishMode) {
713+
insertTextAtCursor(textOutput, ' ');
714+
} else {
715+
if (currentCandidates.length > 0) {
716+
selectCandidate(0);
717+
} else {
718+
insertTextAtCursor(textOutput, ' ');
719+
}
720+
}
721+
} else if (key === '<' || key === '>') {
722+
// handlePageChange is already called by the keyboard click handler
714723
}
715724
updatePhraseLookup();
716725
}
@@ -754,8 +763,8 @@ <h2>查碼練習</h2>
754763
}
755764

756765
// 處理正常的編碼輸入
757-
if (isCodeKey(char)) {
758-
const lowerChar = char.toLowerCase();
766+
const lowerChar = char.toLowerCase();
767+
if (isCodeKey(lowerChar)) {
759768
if (currentCode.length < MAX_CODE_LENGTH) {
760769
currentCode += lowerChar;
761770
} else {
@@ -766,7 +775,6 @@ <h2>查碼練習</h2>
766775
}
767776
updateStateAndDisplay();
768777
} else {
769-
// 如果輸入的不是編碼鍵,則直接輸出
770778
if (currentCode.length > 0) {
771779
if (currentCandidates.length > 0) {
772780
selectCandidate(0);
@@ -779,7 +787,6 @@ <h2>查碼練習</h2>
779787

780788
// --- 處理英文模式輸入的函數 ---
781789
function handleEnglishInput(char) {
782-
// 在英文模式下,除了功能鍵,其他都直接輸出
783790
if (char.length === 1) {
784791
insertTextAtCursor(textOutput, char);
785792
updatePhraseLookup();
@@ -964,26 +971,27 @@ <h2>查碼練習</h2>
964971
}
965972
}
966973

967-
// 處理英文模式
974+
// 處理英文模式,只處理功能鍵
968975
if (isEnglishMode) {
969-
const isFunctionKey = ['Backspace', 'Enter', 'Escape', ' ', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key);
970-
if (!event.shiftKey && !isFunctionKey) {
971-
return; // 讓瀏覽器處理英文大小寫
972-
}
973-
event.preventDefault(); // 阻擋功能鍵
974-
handleFunctionKey(event.key);
975-
} else { // 處理中文模式
976-
const char = event.key;
977-
const isInputKey = isCodeKey(char) || char.match(/^[0-9]$/) || char === ' ' || char === 'Enter' || char === 'Backspace' || char === 'Escape' || char === '<' || char === '>';
978-
979-
if (isInputKey) {
980-
event.preventDefault();
981-
if (char === 'Backspace' || char === 'Enter' || char === 'Escape' || char === ' ' || char === '<' || char === '>') {
982-
handleFunctionKey(char);
983-
} else {
984-
handleChineseInput(char);
985-
}
976+
const isFunctionKey = ['Backspace', 'Enter', 'Escape', ' '].includes(event.key);
977+
if (isFunctionKey) {
978+
event.preventDefault();
979+
handleFunctionKey(event.key);
986980
}
981+
return; // 讓瀏覽器處理其他所有按鍵,包括Shift+英文字母
982+
}
983+
984+
// 處理中文模式
985+
const char = event.key;
986+
const isInputKey = isCodeKey(char) || char.match(/^[0-9]$/) || char === ' ' || char === 'Enter' || char === 'Backspace' || char === 'Escape' || char === '<' || char === '>';
987+
988+
if (isInputKey) {
989+
event.preventDefault();
990+
if (['Backspace', 'Enter', 'Escape', ' ', '<', '>'].includes(char)) {
991+
handleFunctionKey(char);
992+
} else {
993+
handleChineseInput(char);
994+
}
987995
}
988996
});
989997

0 commit comments

Comments
 (0)