Skip to content

Commit 7737f6b

Browse files
authored
Add files via upload
1 parent 6d00f3d commit 7737f6b

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

test.html

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,34 +1019,30 @@ <h2>練打區</h2>
10191019
});
10201020

10211021
function updatePhraseLookup() {
1022-
// The text we want to look up codes for. This should always be the content of the phraseInput.
10231022
const textToSearch = phraseInput.value;
1024-
// The text we want to compare against for coloring. This is the content of the main input area.
10251023
const textToCompare = textOutput.value;
1026-
let cursorPosition;
10271024

1028-
// Determine which textarea has the cursor to get the correct cursor position.
1025+
let lookupStartIndex = 0;
1026+
let highlightIndex = -1; // 使用 -1 表示不需高亮
1027+
10291028
if (phraseInput === document.activeElement) {
1030-
cursorPosition = phraseInput.selectionStart;
1029+
lookupStartIndex = 0; // 當游標在查碼區時,固定從索引 0 開始
10311030
} else if (textOutput === document.activeElement) {
1032-
cursorPosition = textOutput.selectionStart;
1033-
} else {
1034-
cursorPosition = 0; // Default if no focus
1031+
const cursorPosition = textOutput.selectionStart;
1032+
lookupStartIndex = Math.floor(cursorPosition / 10) * 10;
1033+
highlightIndex = cursorPosition; // 當游標在練打區時,高亮游標所在的字
10351034
}
10361035

10371036
encodingResults.innerHTML = '';
10381037

1039-
// The starting index for the 10-character lookup block, based on the cursor position.
1040-
const lookupStartIndex = Math.floor(cursorPosition / 10) * 10;
10411038
const characters = textToSearch.split('').slice(lookupStartIndex, lookupStartIndex + 10);
10421039

1043-
// Fixed loop to display 10 columns
10441040
for (let i = 0; i < 10; i++) {
10451041
const column = document.createElement('div');
10461042
column.className = 'char-encoding-column';
10471043

10481044
const globalIndex = lookupStartIndex + i;
1049-
if (globalIndex === cursorPosition && (phraseInput === document.activeElement || textOutput === document.activeElement)) {
1045+
if (globalIndex === highlightIndex) {
10501046
column.classList.add('highlight-char');
10511047
}
10521048

@@ -1058,10 +1054,8 @@ <h2>練打區</h2>
10581054
charLabel.textContent = char;
10591055

10601056
if (globalIndex < textToCompare.length && char === textToCompare[globalIndex]) {
1061-
// The character at this position matches the typed character.
10621057
charLabel.classList.add('correct-char');
10631058
} else {
1064-
// The character doesn't match or hasn't been typed yet.
10651059
charLabel.classList.add('incorrect-char');
10661060
}
10671061
}

0 commit comments

Comments
 (0)