Normalize countdown keyboard adjustments and roll seconds across minutes

Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
Leon Mika 2026-10-10 06:50:45 +00:00
parent 9c993beda8
commit ebfd6e4ce1
3 changed files with 48 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import { Countdown, integer } from './timer.mjs';
import { Countdown, integer, adjustTime } from './timer.mjs';
const timer = new Countdown();
const minutes = document.querySelector('#minutes');
@ -55,8 +55,10 @@ for (const field of fields) {
if (field.readOnly || !['ArrowUp', 'ArrowDown'].includes(event.key)) return;
event.preventDefault();
const step = event.shiftKey ? 10n : 1n;
const value = integer(field.value) + (event.key === 'ArrowUp' ? step : -step);
field.value = String(value < 0n ? 0n : value);
const adjusted = adjustTime(minutes.value, seconds.value, field.id,
event.key === 'ArrowUp' ? step : -step);
minutes.value = adjusted.minutes;
seconds.value = adjusted.seconds;
edited();
});
field.addEventListener('blur', () => {