Skip to content

Commit

Permalink
Keep capturing characters during debounce
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
qsantos committed Oct 14, 2024
1 parent be2d31a commit d0c5198
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,14 @@ function evaluateTemplate(template, vars) {
return f(...Object.values(vars));
}

/**
* @param {Event} event
*/
function ignoreInputs(event) {
event.preventDefault();
event.stopPropagation();
}

/**
* @param {boolean} debounceStartButton
*/
Expand All @@ -1252,21 +1260,31 @@ function render(debounceStartButton) {
history: [...sessions.map(formatHistoryEntry)].reverse().join(""),
});
restoreSettings();
const currentSession = getElement("current-session", HTMLTextAreaElement);
getElement("language-select", HTMLSelectElement).value = activeLanguage;
getElement("current-session", HTMLTextAreaElement).value = copiedText;
currentSession.value = copiedText;
if (infoMessage) {
const infoElement = getElement("info", HTMLElement);
infoElement.innerHTML = infoMessage;
infoElement.parentElement?.classList.remove("d-none");
}

const startButton = getElement("start-button", HTMLButtonElement);
startButton.focus();
if (debounceStartButton) {
startButton.classList.add("disabled");
// capture all input
currentSession.focus();
currentSession.addEventListener("input", ignoreInputs);
startButton.disabled = true;
// schedule end of debounce
setTimeout(() => {
startButton.classList.remove("disabled");
// restore inputs
currentSession.removeEventListener("input", ignoreInputs);
startButton.disabled = false;
// focus on start button again
startButton.focus();
}, settings.session_debounce_time * 1000);
} else {
startButton.focus();
}
});
}
Expand Down

0 comments on commit d0c5198

Please sign in to comment.