Merge pull request #176 from one-some/shortcuts

Add editor shortcuts and actually fix streaming newline bug
This commit is contained in:
henk717 2022-07-31 12:46:17 +02:00 committed by GitHub
commit bd13a41eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 2 deletions

View File

@ -2335,7 +2335,11 @@ $(document).ready(function(){
} else if (!empty_chunks.has(index.toString())) {
// Append at the end
unbindGametext();
var lc = game_text[0].lastChild;
// game_text can contain things other than chunks (stream
// preview), so we use querySelector to get the last chunk.
var lc = game_text[0].querySelector("chunk:last-of-type");
if(lc.tagName === "CHUNK" && lc.lastChild !== null && lc.lastChild.tagName === "BR") {
lc.removeChild(lc.lastChild);
}
@ -2355,7 +2359,6 @@ $(document).ready(function(){
(element[0].nextSibling === null || element[0].nextSibling.nodeType !== 1 || element[0].nextSibling.tagName !== "CHUNK")
&& element[0].previousSibling !== null
&& element[0].previousSibling.tagName === "CHUNK"
&& !$("#setoutputstreaming")[0].checked
) {
element[0].previousSibling.appendChild(document.createElement("br"));
}
@ -3272,6 +3275,32 @@ $(document).ready(function(){
return true;
}
});
// Shortcuts
$(window).keydown(function (ev) {
// Only ctrl prefixed (for now)
if (!ev.ctrlKey) return;
let handled = true;
switch (ev.key) {
// Ctrl+Z - Back
case "z":
button_actback.click();
break;
// Ctrl+Y - Forward
case "y":
button_actfwd.click();
break;
// Ctrl+E - Retry
case "e":
button_actretry.click();
break;
default:
handled = false;
}
if (handled) ev.preventDefault();
});
});