diff --git a/assets/js/smithwaterman.js b/assets/js/smithwaterman.js index 20652d3..ca38baf 100644 --- a/assets/js/smithwaterman.js +++ b/assets/js/smithwaterman.js @@ -536,5 +536,38 @@ function buildAlignmentCorrect(seq1, seq2, alignmentPath) { return [alignSeq1, alignSeq2]; } +document.addEventListener('DOMContentLoaded', function () { + const table = document.getElementById('tableD'); + + table.addEventListener('keydown', function (event) { + const currentCell = event.target.parentElement; + const currentRow = currentCell.parentElement; + const currentRowIndex = currentRow.rowIndex; + const currentCellIndex = currentCell.cellIndex; + + let nextCell; + + switch (event.key) { + case 'ArrowUp': + nextCell = table.rows[currentRowIndex - 1]?.cells[currentCellIndex]; + break; + case 'ArrowDown': + nextCell = table.rows[currentRowIndex + 1]?.cells[currentCellIndex]; + break; + case 'ArrowLeft': + nextCell = currentCellIndex > 0 ? currentRow.cells[currentCellIndex - 1] : null; + break; + case 'ArrowRight': + nextCell = currentRow.cells[currentCellIndex + 1]; + break; + default: + break; + } + if (nextCell && nextCell.querySelector('input')) { + nextCell.querySelector('input').focus(); + event.preventDefault(); + } + }); + });