Improved input change update responsiveness

This commit is contained in:
n1474335 2022-07-11 13:43:19 +01:00
parent 157dacb3a5
commit 5c8aac5572
5 changed files with 20 additions and 49 deletions

View file

@ -113,7 +113,7 @@ CMYK: ${cmyk}
}).on('colorpickerChange', function(e) { }).on('colorpickerChange', function(e) {
var color = e.color.string('rgba'); var color = e.color.string('rgba');
window.app.manager.input.setInput(color); window.app.manager.input.setInput(color);
window.app.manager.input.debounceInputChange(new Event("keyup")); window.app.manager.input.inputChange(new Event("keyup"));
}); });
</script>`; </script>`;
} }

View file

@ -728,10 +728,11 @@ class App {
* @param {event} e * @param {event} e
*/ */
stateChange(e) { stateChange(e) {
debounce(function() {
this.progress = 0; this.progress = 0;
this.autoBake(); this.autoBake();
this.updateTitle(true, null, true); this.updateTitle(true, null, true);
}, 20, "stateChange", this, [])();
} }

View file

@ -146,7 +146,6 @@ class Manager {
this.addDynamicListener("textarea.arg", "drop", this.recipe.textArgDrop, this.recipe); this.addDynamicListener("textarea.arg", "drop", this.recipe.textArgDrop, this.recipe);
// Input // Input
document.getElementById("input-text").addEventListener("keyup", this.input.debounceInputChange.bind(this.input));
document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app)); document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app));
this.addListeners("#clr-io,#btn-close-all-tabs", "click", this.input.clearAllIoClick, this.input); this.addListeners("#clr-io,#btn-close-all-tabs", "click", this.input.clearAllIoClick, this.input);
this.addListeners("#open-file,#open-folder", "change", this.input.inputOpen, this.input); this.addListeners("#open-file,#open-folder", "change", this.input.inputOpen, this.input);

View file

@ -41,24 +41,6 @@ class InputWaiter {
this.inputTextEl = document.getElementById("input-text"); this.inputTextEl = document.getElementById("input-text");
this.initEditor(); this.initEditor();
// Define keys that don't change the input so we don't have to autobake when they are pressed
this.badKeys = [
16, // Shift
17, // Ctrl
18, // Alt
19, // Pause
20, // Caps
27, // Esc
33, 34, 35, 36, // PgUp, PgDn, End, Home
37, 38, 39, 40, // Directional
44, // PrntScrn
91, 92, // Win
93, // Context
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, // F1-12
144, // Num
145, // Scroll
];
this.inputWorker = null; this.inputWorker = null;
this.loaderWorkers = []; this.loaderWorkers = [];
this.workerId = 0; this.workerId = 0;
@ -125,6 +107,8 @@ class InputWaiter {
EditorView.updateListener.of(e => { EditorView.updateListener.of(e => {
if (e.selectionSet) if (e.selectionSet)
this.manager.highlighter.selectionChange("input", e); this.manager.highlighter.selectionChange("input", e);
if (e.docChanged)
this.inputChange(e);
}) })
] ]
}); });
@ -396,7 +380,7 @@ class InputWaiter {
this.showLoadingInfo(r.data, true); this.showLoadingInfo(r.data, true);
break; break;
case "setInput": case "setInput":
debounce(this.set, 50, "setInput", this, [r.data.inputObj, r.data.silent])(); this.set(r.data.inputObj, r.data.silent);
break; break;
case "inputAdded": case "inputAdded":
this.inputAdded(r.data.changeTab, r.data.inputNum); this.inputAdded(r.data.changeTab, r.data.inputNum);
@ -762,25 +746,17 @@ class InputWaiter {
}); });
} }
/**
* Handler for input change events.
* Debounces the input so we don't call autobake too often.
*
* @param {event} e
*/
debounceInputChange(e) {
debounce(this.inputChange, 50, "inputChange", this, [e])();
}
/** /**
* Handler for input change events. * Handler for input change events.
* Updates the value stored in the inputWorker * Updates the value stored in the inputWorker
* Debounces the input so we don't call autobake too often.
* *
* @param {event} e * @param {event} e
* *
* @fires Manager#statechange * @fires Manager#statechange
*/ */
inputChange(e) { inputChange(e) {
debounce(function(e) {
// Ignore this function if the input is a file // Ignore this function if the input is a file
const fileOverlay = document.getElementById("input-file"); const fileOverlay = document.getElementById("input-file");
if (fileOverlay.style.display === "block") return; if (fileOverlay.style.display === "block") return;
@ -788,15 +764,12 @@ class InputWaiter {
const value = this.getInput(); const value = this.getInput();
const activeTab = this.manager.tabs.getActiveInputTab(); const activeTab = this.manager.tabs.getActiveInputTab();
this.app.progress = 0;
this.updateInputValue(activeTab, value); this.updateInputValue(activeTab, value);
this.manager.tabs.updateInputTabHeader(activeTab, value.slice(0, 100).replace(/[\n\r]/g, "")); this.manager.tabs.updateInputTabHeader(activeTab, value.slice(0, 100).replace(/[\n\r]/g, ""));
if (e && this.badKeys.indexOf(e.keyCode) < 0) {
// Fire the statechange event as the input has been modified // Fire the statechange event as the input has been modified
window.dispatchEvent(this.manager.statechange); window.dispatchEvent(this.manager.statechange);
} }, 20, "inputChange", this, [e])();
} }
/** /**

View file

@ -847,9 +847,7 @@ class OutputWaiter {
} }
} }
debounce(this.set, 50, "setOutput", this, [inputNum])(); this.set(inputNum);
this.outputTextEl.scroll(0, 0); // TODO
if (changeInput) { if (changeInput) {
this.manager.input.changeTab(inputNum, false); this.manager.input.changeTab(inputNum, false);