Skip to content

Commit

Permalink
fixed function() highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
axjh03 committed May 1, 2024
1 parent 7b2481a commit 86c6273
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions src/main/webapp/html/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function toggleCell(cell, value) {
if (!confirmedCells.has(cellId)) {
// Only toggle if not confirmed as correct
if (cell.style.backgroundColor === "cyan") {
cell.style.backgroundColor = "";
cell.style.backgroundColor = "green";
removeFromSelected(value);
} else {
cell.style.backgroundColor = "cyan";
Expand Down Expand Up @@ -277,39 +277,11 @@ function clearSelection() {
}


function highlightWords(wordsPositions, isPermanent = false) {
// Initialize the sets if they are not already defined
if (typeof confirmedCells === 'undefined') {
window.confirmedCells = new Set(); // Temporary highlights
}
if (typeof permanentConfirmedCells === 'undefined') {
window.permanentConfirmedCells = new Set(); // Permanent highlights
}

// Clear temporary highlights that are not permanent
confirmedCells.forEach(cellId => {
if (!permanentConfirmedCells.has(cellId)) {
const cell = document.getElementById(cellId);
if (cell) {
cell.style.backgroundColor = ""; // Reset the background color
}
}
});
confirmedCells.clear();

// Highlight new words
wordsPositions.forEach(pos => {
const cellId = `cell_${pos[0]}_${pos[1]}`;
const cell = document.getElementById(cellId);
if (cell) { // Check if cell actually exists
if (isPermanent) {
cell.style.backgroundColor = "green"; // Use a different color for permanent if needed
permanentConfirmedCells.add(cellId); // Add to permanent list
} else if (!permanentConfirmedCells.has(cellId)) {
cell.style.backgroundColor = "lightgreen"; // Temporary color
confirmedCells.add(cellId); // Add to temporary list
}
}
function highlightWords(wordsPositions) {
wordsPositions.forEach((pos) => {
let cell = document.getElementById(`cell_${pos[0]}_${pos[1]}`);
cell.style.backgroundColor = "green";
confirmedCells.add(cell.id); // Add to confirmed list
});
}

Expand Down

0 comments on commit 86c6273

Please sign in to comment.