"...git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "cc8795c68aba7b7c5ef2e77fe559c04b74045a6f"
Unverified Commit a7c7da68 authored by missionfloyd's avatar missionfloyd Committed by GitHub
Browse files

Editattention setting (#533)



* Add editAttention delta setting

* Update editAttention.js

* Update web/extensions/core/editAttention.js
Co-authored-by: default avatarKarun <karun.ellango7@gmail.com>

* Update editAttention.js

* Update editAttention.js

* Fix setting value

---------
Co-authored-by: default avatarKarun <karun.ellango7@gmail.com>
parent b9b1df30
......@@ -2,10 +2,21 @@ import { app } from "/scripts/app.js";
// Allows you to edit the attention weight by holding ctrl (or cmd) and using the up/down arrow keys
const id = "Comfy.EditAttention";
app.registerExtension({
name:id,
name: "Comfy.EditAttention",
init() {
const editAttentionDelta = app.ui.settings.addSetting({
id: "Comfy.EditAttention.Delta",
name: "Ctrl+up/down precision",
type: "slider",
attrs: {
min: 0.01,
max: 2,
step: 0.01,
},
defaultValue: 0.1,
});
function incrementWeight(weight, delta) {
const floatWeight = parseFloat(weight);
if (isNaN(floatWeight)) return weight;
......@@ -58,7 +69,7 @@ name:id,
function editAttention(event) {
const inputField = event.composedPath()[0];
const delta = 0.025;
const delta = parseFloat(editAttentionDelta.value);
if (inputField.tagName !== "TEXTAREA") return;
if (!(event.key === "ArrowUp" || event.key === "ArrowDown")) return;
......@@ -125,7 +136,7 @@ name:id,
// Increment the weight
const weightDelta = event.key === "ArrowUp" ? delta : -delta;
const updatedText = selectedText.replace(/(.*:)(\d+(\.\d+)?)(.*)/, (match, prefix, weight, _, suffix) => {
return prefix + incrementWeight(weight, weightDelta) + suffix;
return prefix + incrementWeight(weight, weightDelta) + suffix;
});
inputField.setRangeText(updatedText, start, end, "select");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment