forked from extern/easydiffusion
Moving attention weighting to InvokeAI syntax (#1055)
* Moving attention weighting to InvokeAI syntax () and [] were actually ignored by the legacy parser, so moving the Ctrl+Wheel shortcut to the InvokeAI syntax of '+' and '-'. * Moving attention weighting to InvokeAI syntax () and [] were actually ignored by the legacy parser, so moving the Ctrl+Wheel shortcut to the InvokeAI syntax of '+' and '-'. * Properly cleanup parenthesis '(image tag)++' need to be trimmed to 'image tag' * Add parenthesis as needed when adjusting weights In the InvokeAI syntax, 'image modifier' must become '(image modifier)++' when adjusting weight. * Code cleanup
This commit is contained in:
parent
d81be64711
commit
a10dfd0386
@ -129,7 +129,10 @@ function createModifierGroup(modifierGroup, initiallyExpanded, removeBy) {
|
||||
}
|
||||
|
||||
function trimModifiers(tag) {
|
||||
return tag.replace(/^\(+|\)+$/g, '').replace(/^\[+|\]+$/g, '')
|
||||
// Remove trailing '-' and/or '+'
|
||||
tag = tag.replace(/[-+]+$/, '');
|
||||
// Remove parentheses at beginning and end
|
||||
return tag.replace(/^[(]+|[\s)]+$/g, '');
|
||||
}
|
||||
|
||||
async function loadModifiers() {
|
||||
|
@ -1,4 +1,8 @@
|
||||
(function () { "use strict"
|
||||
(function () {
|
||||
"use strict"
|
||||
|
||||
const MAX_WEIGHT = 5
|
||||
|
||||
if (typeof editorModifierTagsList !== 'object') {
|
||||
console.error('editorModifierTagsList missing...')
|
||||
return
|
||||
@ -34,34 +38,42 @@
|
||||
break
|
||||
}
|
||||
}
|
||||
if (s.charAt(0) !== '(' && s.charAt(s.length - 1) !== ')' && s.trim().includes(' ')) {
|
||||
s = '(' + s + ')'
|
||||
t = '(' + t + ')'
|
||||
}
|
||||
if (delta < 0) {
|
||||
// wheel scrolling up
|
||||
if (s.substring(0, 1) == '[' && s.substring(s.length-1) == ']') {
|
||||
s = s.substring(1, s.length - 1)
|
||||
t = t.substring(1, t.length - 1)
|
||||
if (s.substring(s.length - 1) == '-') {
|
||||
s = s.substring(0, s.length - 1)
|
||||
t = t.substring(0, t.length - 1)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s.substring(0, 10) !== '('.repeat(10) && s.substring(s.length-10) !== ')'.repeat(10)) {
|
||||
s = '(' + s + ')'
|
||||
t = '(' + t + ')'
|
||||
if (s.substring(s.length - MAX_WEIGHT) !== '+'.repeat(MAX_WEIGHT)) {
|
||||
s = s + '+'
|
||||
t = t + '+'
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
// wheel scrolling down
|
||||
if (s.substring(0, 1) == '(' && s.substring(s.length-1) == ')') {
|
||||
s = s.substring(1, s.length - 1)
|
||||
t = t.substring(1, t.length - 1)
|
||||
if (s.substring(s.length - 1) == '+') {
|
||||
s = s.substring(0, s.length - 1)
|
||||
t = t.substring(0, t.length - 1)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s.substring(0, 10) !== '['.repeat(10) && s.substring(s.length-10) !== ']'.repeat(10)) {
|
||||
s = '[' + s + ']'
|
||||
t = '[' + t + ']'
|
||||
if (s.substring(s.length - MAX_WEIGHT) !== '-'.repeat(MAX_WEIGHT)) {
|
||||
s = s + '-'
|
||||
t = t + '-'
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.charAt(0) === '(' && s.charAt(s.length - 1) === ')') {
|
||||
s = s.substring(1, s.length - 1)
|
||||
t = t.substring(1, t.length - 1)
|
||||
}
|
||||
i.parentElement.getElementsByClassName('modifier-card-label')[0].getElementsByTagName("p")[0].innerText = s
|
||||
// update activeTags
|
||||
for (let it = 0; it < overlays.length; it++) {
|
||||
|
Loading…
Reference in New Issue
Block a user