From 5fb453272a07d09d417912c90405dab7dc46eadd Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 5 Feb 2020 10:36:35 -0500 Subject: [PATCH] Avoid changing an option that was just set Option fields were getting updated right after a value was entered, preventing more numbers from being typed. Fields are now skipped if their change was what prompted an update. --- macrovision.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/macrovision.js b/macrovision.js index 2c26d0d4..b0f8e5d6 100644 --- a/macrovision.js +++ b/macrovision.js @@ -422,14 +422,14 @@ function configViewOptions(entity, view) { entity.views[view][key] = math.unit(input.value, select.value); updateSizes(); updateEntityOptions(entity, view); - updateViewOptions(entity, view); + updateViewOptions(entity, view, key); }); select.addEventListener("input", e => { entity.views[view][key] = math.unit(input.value, select.value); updateSizes(); updateEntityOptions(entity, view); - updateViewOptions(entity, view); + updateViewOptions(entity, view, key); }); row.appendChild(input); @@ -438,14 +438,17 @@ function configViewOptions(entity, view) { } -function updateViewOptions(entity, view) { +function updateViewOptions(entity, view, changed) { Object.entries(entity.views[view].attributes).forEach(([key, val]) => { - const input = document.querySelector("#options-view-" + key + "-input"); - const select = document.querySelector("#options-view-" + key + "-select"); - const currentUnit = select.value; - const convertedAmount = entity.views[view][key].to(currentUnit); - console.log(convertedAmount); - input.value = convertedAmount.value; + if (key != changed) { + const input = document.querySelector("#options-view-" + key + "-input"); + const select = document.querySelector("#options-view-" + key + "-select"); + const currentUnit = select.value; + const convertedAmount = entity.views[view][key].to(currentUnit); + console.log(convertedAmount); + input.value = math.round(convertedAmount.value, 5); + } + }); }