(event, fileName)
| 379 | } |
| 380 | |
| 381 | export function toggleRowSelection(event, fileName) { |
| 382 | // Prevent default text selection when shift is held. |
| 383 | if (event.shiftKey) { |
| 384 | event.preventDefault(); |
| 385 | } |
| 386 | |
| 387 | // Ignore clicks on interactive elements. |
| 388 | const targetTag = event.target.tagName.toLowerCase(); |
| 389 | if (["a", "button", "input"].includes(targetTag)) { |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | // Get the clicked row and its checkbox. |
| 394 | const row = event.currentTarget; |
| 395 | const checkbox = row.querySelector(".file-checkbox"); |
| 396 | if (!checkbox) return; |
| 397 | |
| 398 | // Get all rows in the current file list view. |
| 399 | const allRows = Array.from(document.querySelectorAll("#fileList tbody tr")); |
| 400 | |
| 401 | // Helper: clear all selections (not used in this updated version). |
| 402 | const clearAllSelections = () => { |
| 403 | allRows.forEach(r => { |
| 404 | const cb = r.querySelector(".file-checkbox"); |
| 405 | if (cb) { |
| 406 | cb.checked = false; |
| 407 | updateRowHighlight(cb); |
| 408 | } |
| 409 | }); |
| 410 | }; |
| 411 | |
| 412 | // If the user is holding the Shift key, perform range selection. |
| 413 | if (event.shiftKey) { |
| 414 | // Use the last clicked row as the anchor. |
| 415 | const lastRow = window.lastSelectedFileRow || row; |
| 416 | const currentIndex = allRows.indexOf(row); |
| 417 | const lastIndex = allRows.indexOf(lastRow); |
| 418 | const start = Math.min(currentIndex, lastIndex); |
| 419 | const end = Math.max(currentIndex, lastIndex); |
| 420 | |
| 421 | for (let i = start; i <= end; i++) { |
| 422 | const cb = allRows[i].querySelector(".file-checkbox"); |
| 423 | if (cb) { |
| 424 | cb.checked = true; |
| 425 | updateRowHighlight(cb); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | // Otherwise, for all non-shift clicks simply toggle the selected state. |
| 430 | else { |
| 431 | checkbox.checked = !checkbox.checked; |
| 432 | updateRowHighlight(checkbox); |
| 433 | } |
| 434 | |
| 435 | // Update the anchor row to the row that was clicked. |
| 436 | window.lastSelectedFileRow = row; |
| 437 | updateFileActionButtons(); |
| 438 | } |
no test coverage detected