Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
26215661
Commit
26215661
authored
Jan 22, 2023
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attention ctrl+up/down enhancements
parent
fbb25fab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
47 deletions
+71
-47
javascript/edit-attention.js
javascript/edit-attention.js
+66
-44
modules/shared.py
modules/shared.py
+5
-3
No files found.
javascript/edit-attention.js
View file @
26215661
addEventListener
(
'
keydown
'
,
(
event
)
=>
{
function
keyupEditAttention
(
event
)
{
let
target
=
event
.
originalTarget
||
event
.
composedPath
()[
0
];
let
target
=
event
.
originalTarget
||
event
.
composedPath
()[
0
];
if
(
!
target
.
matches
(
"
[id*='_toprow'] textarea.gr-text-input[placeholder]
"
))
return
;
if
(
!
target
.
matches
(
"
[id*='_toprow'] textarea.gr-text-input[placeholder]
"
))
return
;
if
(
!
(
event
.
metaKey
||
event
.
ctrlKey
))
return
;
if
(
!
(
event
.
metaKey
||
event
.
ctrlKey
))
return
;
let
isPlus
=
event
.
key
==
"
ArrowUp
"
let
plus
=
"
ArrowUp
"
let
isMinus
=
event
.
key
==
"
ArrowDown
"
let
minus
=
"
ArrowDown
"
if
(
!
isPlus
&&
!
isMinus
)
return
;
if
(
event
.
key
!=
plus
&&
event
.
key
!=
minus
)
return
;
let
selectionStart
=
target
.
selectionStart
;
let
selectionStart
=
target
.
selectionStart
;
let
selectionEnd
=
target
.
selectionEnd
;
let
selectionEnd
=
target
.
selectionEnd
;
// If the user hasn't selected anything, let's select their current parenthesis block
let
text
=
target
.
value
;
if
(
selectionStart
===
selectionEnd
)
{
function
selectCurrentParenthesisBlock
(
OPEN
,
CLOSE
){
if
(
selectionStart
!==
selectionEnd
)
return
false
;
// Find opening parenthesis around current cursor
// Find opening parenthesis around current cursor
const
before
=
t
arget
.
value
.
substring
(
0
,
selectionStart
);
const
before
=
t
ext
.
substring
(
0
,
selectionStart
);
let
beforeParen
=
before
.
lastIndexOf
(
"
(
"
);
let
beforeParen
=
before
.
lastIndexOf
(
OPEN
);
if
(
beforeParen
==
-
1
)
return
;
if
(
beforeParen
==
-
1
)
return
false
;
let
beforeParenClose
=
before
.
lastIndexOf
(
"
)
"
);
let
beforeParenClose
=
before
.
lastIndexOf
(
CLOSE
);
while
(
beforeParenClose
!==
-
1
&&
beforeParenClose
>
beforeParen
)
{
while
(
beforeParenClose
!==
-
1
&&
beforeParenClose
>
beforeParen
)
{
beforeParen
=
before
.
lastIndexOf
(
"
(
"
,
beforeParen
-
1
);
beforeParen
=
before
.
lastIndexOf
(
OPEN
,
beforeParen
-
1
);
beforeParenClose
=
before
.
lastIndexOf
(
"
)
"
,
beforeParenClose
-
1
);
beforeParenClose
=
before
.
lastIndexOf
(
CLOSE
,
beforeParenClose
-
1
);
}
}
// Find closing parenthesis around current cursor
// Find closing parenthesis around current cursor
const
after
=
t
arget
.
value
.
substring
(
selectionStart
);
const
after
=
t
ext
.
substring
(
selectionStart
);
let
afterParen
=
after
.
indexOf
(
"
)
"
);
let
afterParen
=
after
.
indexOf
(
CLOSE
);
if
(
afterParen
==
-
1
)
return
;
if
(
afterParen
==
-
1
)
return
false
;
let
afterParenOpen
=
after
.
indexOf
(
"
(
"
);
let
afterParenOpen
=
after
.
indexOf
(
OPEN
);
while
(
afterParenOpen
!==
-
1
&&
afterParen
>
afterParenOpen
)
{
while
(
afterParenOpen
!==
-
1
&&
afterParen
>
afterParenOpen
)
{
afterParen
=
after
.
indexOf
(
"
)
"
,
afterParen
+
1
);
afterParen
=
after
.
indexOf
(
CLOSE
,
afterParen
+
1
);
afterParenOpen
=
after
.
indexOf
(
"
(
"
,
afterParenOpen
+
1
);
afterParenOpen
=
after
.
indexOf
(
OPEN
,
afterParenOpen
+
1
);
}
}
if
(
beforeParen
===
-
1
||
afterParen
===
-
1
)
return
;
if
(
beforeParen
===
-
1
||
afterParen
===
-
1
)
return
false
;
// Set the selection to the text between the parenthesis
// Set the selection to the text between the parenthesis
const
parenContent
=
t
arget
.
value
.
substring
(
beforeParen
+
1
,
selectionStart
+
afterParen
);
const
parenContent
=
t
ext
.
substring
(
beforeParen
+
1
,
selectionStart
+
afterParen
);
const
lastColon
=
parenContent
.
lastIndexOf
(
"
:
"
);
const
lastColon
=
parenContent
.
lastIndexOf
(
"
:
"
);
selectionStart
=
beforeParen
+
1
;
selectionStart
=
beforeParen
+
1
;
selectionEnd
=
selectionStart
+
lastColon
;
selectionEnd
=
selectionStart
+
lastColon
;
target
.
setSelectionRange
(
selectionStart
,
selectionEnd
);
target
.
setSelectionRange
(
selectionStart
,
selectionEnd
);
}
return
true
;
}
// If the user hasn't selected anything, let's select their current parenthesis block
if
(
!
selectCurrentParenthesisBlock
(
'
<
'
,
'
>
'
)){
selectCurrentParenthesisBlock
(
'
(
'
,
'
)
'
)
}
event
.
preventDefault
();
event
.
preventDefault
();
if
(
selectionStart
==
0
||
target
.
value
[
selectionStart
-
1
]
!=
"
(
"
)
{
closeCharacter
=
'
)
'
target
.
value
=
target
.
value
.
slice
(
0
,
selectionStart
)
+
delta
=
opts
.
keyedit_precision_attention
"
(
"
+
target
.
value
.
slice
(
selectionStart
,
selectionEnd
)
+
"
:1.0)
"
+
target
.
value
.
slice
(
selectionEnd
);
if
(
selectionStart
>
0
&&
text
[
selectionStart
-
1
]
==
'
<
'
){
closeCharacter
=
'
>
'
delta
=
opts
.
keyedit_precision_extra
}
else
if
(
selectionStart
==
0
||
text
[
selectionStart
-
1
]
!=
"
(
"
)
{
// do not include spaces at the end
while
(
selectionEnd
>
selectionStart
&&
text
[
selectionEnd
-
1
]
==
'
'
){
selectionEnd
-=
1
;
}
if
(
selectionStart
==
selectionEnd
){
return
}
target
.
focus
();
text
=
text
.
slice
(
0
,
selectionStart
)
+
"
(
"
+
text
.
slice
(
selectionStart
,
selectionEnd
)
+
"
:1.0)
"
+
text
.
slice
(
selectionEnd
);
target
.
selectionStart
=
selectionStart
+
1
;
target
.
selectionEnd
=
selectionEnd
+
1
;
}
else
{
selectionStart
+=
1
;
end
=
target
.
value
.
slice
(
selectionEnd
+
1
).
indexOf
(
"
)
"
)
+
1
;
selectionEnd
+=
1
;
weight
=
parseFloat
(
target
.
value
.
slice
(
selectionEnd
+
1
,
selectionEnd
+
1
+
end
));
}
if
(
isNaN
(
weight
))
return
;
if
(
event
.
key
==
minus
)
weight
-=
0.1
;
if
(
event
.
key
==
plus
)
weight
+=
0.1
;
weight
=
parseFloat
(
weight
.
toPrecision
(
12
));
end
=
text
.
slice
(
selectionEnd
+
1
).
indexOf
(
closeCharacter
)
+
1
;
weight
=
parseFloat
(
text
.
slice
(
selectionEnd
+
1
,
selectionEnd
+
1
+
end
));
if
(
isNaN
(
weight
))
return
;
target
.
value
=
target
.
value
.
slice
(
0
,
selectionEnd
+
1
)
+
weight
+=
isPlus
?
delta
:
-
delta
;
weight
+
weight
=
parseFloat
(
weight
.
toPrecision
(
12
));
target
.
value
.
slice
(
selectionEnd
+
1
+
end
-
1
);
if
(
String
(
weight
).
length
==
1
)
weight
+=
"
.0
"
target
.
focus
();
text
=
text
.
slice
(
0
,
selectionEnd
+
1
)
+
weight
+
text
.
slice
(
selectionEnd
+
1
+
end
-
1
);
target
.
selectionStart
=
selectionStart
;
target
.
selectionEnd
=
selectionEnd
;
target
.
focus
();
}
target
.
value
=
text
;
target
.
selectionStart
=
selectionStart
;
target
.
selectionEnd
=
selectionEnd
;
updateInput
(
target
)
updateInput
(
target
)
});
}
addEventListener
(
'
keydown
'
,
(
event
)
=>
{
keyupEditAttention
(
event
);
});
\ No newline at end of file
modules/shared.py
View file @
26215661
...
@@ -444,9 +444,11 @@ options_templates.update(options_section(('ui', "User interface"), {
...
@@ -444,9 +444,11 @@ options_templates.update(options_section(('ui', "User interface"), {
"show_progress_in_title"
:
OptionInfo
(
True
,
"Show generation progress in window title."
),
"show_progress_in_title"
:
OptionInfo
(
True
,
"Show generation progress in window title."
),
"samplers_in_dropdown"
:
OptionInfo
(
True
,
"Use dropdown for sampler selection instead of radio group"
),
"samplers_in_dropdown"
:
OptionInfo
(
True
,
"Use dropdown for sampler selection instead of radio group"
),
"dimensions_and_batch_together"
:
OptionInfo
(
True
,
"Show Width/Height and Batch sliders in same row"
),
"dimensions_and_batch_together"
:
OptionInfo
(
True
,
"Show Width/Height and Batch sliders in same row"
),
'quicksettings'
:
OptionInfo
(
"sd_model_checkpoint"
,
"Quicksettings list"
),
"keyedit_precision_attention"
:
OptionInfo
(
0.1
,
"Ctrl+up/down precision when editing (attention:1.1)"
,
gr
.
Slider
,
{
"minimum"
:
0.01
,
"maximum"
:
0.2
,
"step"
:
0.001
}),
'ui_reorder'
:
OptionInfo
(
", "
.
join
(
ui_reorder_categories
),
"txt2img/img2img UI item order"
),
"keyedit_precision_extra"
:
OptionInfo
(
0.05
,
"Ctrl+up/down precision when editing <extra networks:0.9>"
,
gr
.
Slider
,
{
"minimum"
:
0.01
,
"maximum"
:
0.2
,
"step"
:
0.001
}),
'localization'
:
OptionInfo
(
"None"
,
"Localization (requires restart)"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
[
"None"
]
+
list
(
localization
.
localizations
.
keys
())},
refresh
=
lambda
:
localization
.
list_localizations
(
cmd_opts
.
localizations_dir
)),
"quicksettings"
:
OptionInfo
(
"sd_model_checkpoint"
,
"Quicksettings list"
),
"ui_reorder"
:
OptionInfo
(
", "
.
join
(
ui_reorder_categories
),
"txt2img/img2img UI item order"
),
"localization"
:
OptionInfo
(
"None"
,
"Localization (requires restart)"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
[
"None"
]
+
list
(
localization
.
localizations
.
keys
())},
refresh
=
lambda
:
localization
.
list_localizations
(
cmd_opts
.
localizations_dir
)),
}))
}))
options_templates
.
update
(
options_section
((
'ui'
,
"Live previews"
),
{
options_templates
.
update
(
options_section
((
'ui'
,
"Live previews"
),
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment