This commit is contained in:
Mário Panenko 2024-11-23 14:59:41 +00:00
parent d68e0f14c7
commit 28468a596f

View File

@ -103,22 +103,27 @@ async function loadVideoSequenceByLetters() {
currentIndex = 0; currentIndex = 0;
} }
// Function to highlight the current word or letter // Function to highlight the current word or letter in the textarea
function highlightCurrentText(index) { function highlightCurrentText(index) {
let wordsOrLetters = currentTranslationMode === 'words' ? inputText.value.trim().split(' ') : inputText.value.trim().split(''); let wordsOrLetters = currentTranslationMode === 'words' ? inputText.value.trim().split(' ') : inputText.value.trim().split('');
// Reset the text content and remove previous highlights // Reset the highlighted text in the textarea
inputText.innerHTML = ''; inputText.value = '';
inputText.setSelectionRange(0, 0);
// Rebuild the text content with highlighting let startIndex = 0;
wordsOrLetters.forEach((item, i) => { wordsOrLetters.forEach((item, i) => {
const span = document.createElement('span'); if (i < index) {
span.textContent = item + (currentTranslationMode === 'words' ? ' ' : ''); startIndex += item.length + (currentTranslationMode === 'words' ? 1 : 0);
if (i === index) {
span.classList.add('highlight');
} }
inputText.appendChild(span);
}); });
let endIndex = startIndex + wordsOrLetters[index].length;
inputText.value = wordsOrLetters.join(currentTranslationMode === 'words' ? ' ' : '');
// Highlight the current word or letter
inputText.setSelectionRange(startIndex, endIndex);
inputText.focus();
} }
// Function to play video at a specific index // Function to play video at a specific index