Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(playground): add keyboard shortcut for submit (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
peakji authored Mar 29, 2023
1 parent 086cb76 commit 5253bcd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions basaran/static/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ class Completion extends EventTarget {
if (highlight) {
span.setAttribute(
"style",
`background-color: rgba(70, 120, 220, ${
0.5 * prob
})`
`background-color: rgba(70, 120, 220, ${0.5 * prob})`
);
}
}
Expand Down Expand Up @@ -422,10 +420,11 @@ class Inspector {

handles.set(presets[0]);

let submit = document.querySelector(".pg-submit");
let prompt = document.querySelector(".pg-prompt");
let outputs = document.querySelector(".pg-outputs");

document.querySelector(".pg-submit").addEventListener("click", (e) => {
submit.addEventListener("click", (e) => {
if (completion) {
if (completion.running) {
completion.stop();
Expand All @@ -452,6 +451,13 @@ class Inspector {
});
});

document.addEventListener("keydown", (e) => {
if ((e.ctrlKey || e.metaKey) && e.key == "Enter") {
e.preventDefault();
submit.click();
}
});

let resizePrompt = () => {
prompt.style.height = 0;
prompt.style.height = prompt.scrollHeight + "px";
Expand Down

0 comments on commit 5253bcd

Please sign in to comment.