Skip to content

Commit

Permalink
Restore the focus automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Jul 30, 2024
1 parent 008778f commit 06df265
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/renderer/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const deletedDataAttr = "data-deleted";
const searchHiddenDataAttr = "data-search-hidden";
/** The `name` attribute of the details element */
const detailsName = "transitio-setting-details";
/** The expiration time of the last focused variable */
const lastFocusedExpire = 1000;
/** Last focused style path, variable name and expiration time */
let lastFocused = [null, null, 0];

/** Function to parse the value from the input/select element.
* @param {Element} varInput The input/select element.
Expand Down Expand Up @@ -333,6 +337,7 @@ function transitioSettingsUpdateStyle(container, args) {
if (noVariables) { // Close the details if there are no variables
details.toggleAttribute("open", false);
}
const isLastFocusedStyle = lastFocused[0] === path;
for (const [name, varObj] of Object.entries(meta.variables)) {
const varItem = details.appendChild(document.createElement("setting-item"));
varItem.setAttribute("data-direction", "row");
Expand All @@ -342,9 +347,14 @@ function transitioSettingsUpdateStyle(container, args) {
const varInput = varItem.appendChild(constructVarInput(varObj));
varInput.addEventListener("change", () => {
if (varInput.reportValidity()) {
lastFocused = [path, name, Date.now() + lastFocusedExpire]; // Remember the last focused variable
transitio.configChange(path, { [name]: getValueFromInput(varInput) });
}
});
if (isLastFocusedStyle && lastFocused[1] === name && lastFocused[2] > Date.now()) {
varInput.focus(); // Restore the focus
lastFocused = [null, null, 0]; // Clear the last focused variable
}
}
log("onUpdateStyle", path, enabled);
}
Expand Down

0 comments on commit 06df265

Please sign in to comment.