diff options
author | InvincibleDude <81354513+InvincibleDude@users.noreply.github.com> | 2023-01-30 12:35:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-30 12:35:13 +0000 |
commit | 3ec2eb8bf12ae629c292ed0e96f199669040c5de (patch) | |
tree | fb46cb76c06f4c6a5ad4ad2ce8cd3a4577525be5 /javascript/ui.js | |
parent | 0d834b9394bb1a9dbcbdc02a3d4d24d1e6511073 (diff) | |
parent | ee9fdf7f62984dc30770fb1a73e68736b319746f (diff) | |
download | stable-diffusion-webui-gfx803-3ec2eb8bf12ae629c292ed0e96f199669040c5de.tar.gz stable-diffusion-webui-gfx803-3ec2eb8bf12ae629c292ed0e96f199669040c5de.tar.bz2 stable-diffusion-webui-gfx803-3ec2eb8bf12ae629c292ed0e96f199669040c5de.zip |
Merge branch 'master' into improved-hr-conflict-test
Diffstat (limited to 'javascript/ui.js')
-rw-r--r-- | javascript/ui.js | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/javascript/ui.js b/javascript/ui.js index dd40e62d..b7a8268a 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -191,6 +191,28 @@ function confirm_clear_prompt(prompt, negative_prompt) { return [prompt, negative_prompt] } + +promptTokecountUpdateFuncs = {} + +function recalculatePromptTokens(name){ + if(promptTokecountUpdateFuncs[name]){ + promptTokecountUpdateFuncs[name]() + } +} + +function recalculate_prompts_txt2img(){ + recalculatePromptTokens('txt2img_prompt') + recalculatePromptTokens('txt2img_neg_prompt') + return args_to_array(arguments); +} + +function recalculate_prompts_img2img(){ + recalculatePromptTokens('img2img_prompt') + recalculatePromptTokens('img2img_neg_prompt') + return args_to_array(arguments); +} + + opts = {} onUiUpdate(function(){ if(Object.keys(opts).length != 0) return; @@ -232,14 +254,12 @@ onUiUpdate(function(){ return } - prompt.parentElement.insertBefore(counter, prompt) counter.classList.add("token-counter") prompt.parentElement.style.position = "relative" - textarea.addEventListener("input", function(){ - update_token_counter(id_button); - }); + promptTokecountUpdateFuncs[id] = function(){ update_token_counter(id_button); } + textarea.addEventListener("input", promptTokecountUpdateFuncs[id]); } registerTextarea('txt2img_prompt', 'txt2img_token_counter', 'txt2img_token_button') @@ -273,7 +293,7 @@ onOptionsChanged(function(){ let txt2img_textarea, img2img_textarea = undefined; let wait_time = 800 -let token_timeout; +let token_timeouts = {}; function update_txt2img_tokens(...args) { update_token_counter("txt2img_token_button") @@ -290,9 +310,9 @@ function update_img2img_tokens(...args) { } function update_token_counter(button_id) { - if (token_timeout) - clearTimeout(token_timeout); - token_timeout = setTimeout(() => gradioApp().getElementById(button_id)?.click(), wait_time); + if (token_timeouts[button_id]) + clearTimeout(token_timeouts[button_id]); + token_timeouts[button_id] = setTimeout(() => gradioApp().getElementById(button_id)?.click(), wait_time); } function restart_reload(){ |