Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
88e315a8
Commit
88e315a8
authored
Sep 17, 2022
by
Connum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace existing images when pasting from clipboard or dropping a new one (fixes #573)
parent
23a0ec04
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
4 deletions
+45
-4
script.js
script.js
+45
-4
No files found.
script.js
View file @
88e315a8
...
@@ -326,12 +326,51 @@ function submit(){
...
@@ -326,12 +326,51 @@ function submit(){
return
res
return
res
}
}
window
.
addEventListener
(
'paste'
,
e
=>
{
function
isValidImageList
(
files
)
{
const
files
=
e
.
clipboardData
.
files
;
return
files
&&
files
?.
length
===
1
&&
[
'image/png'
,
'image/gif'
,
'image/jpeg'
].
includes
(
files
[
0
].
type
);
if
(
!
files
||
files
.
length
!==
1
)
{
}
function
dropReplaceImage
(
imgWrap
,
files
)
{
if
(
!
isValidImageList
(
files
)
)
{
return
;
return
;
}
}
if
(
!
[
'image/png'
,
'image/gif'
,
'image/jpeg'
].
includes
(
files
[
0
].
type
))
{
imgWrap
.
querySelector
(
'.modify-upload button + button'
)?.
click
();
window
.
requestAnimationFrame
(
()
=>
{
const
fileInput
=
imgWrap
.
querySelector
(
'input[type="file"]'
);
if
(
fileInput
)
{
fileInput
.
files
=
files
;
fileInput
.
dispatchEvent
(
new
Event
(
'change'
));
}
});
}
window
.
document
.
addEventListener
(
'dragover'
,
e
=>
{
const
target
=
e
.
composedPath
()[
0
];
const
imgWrap
=
target
.
closest
(
'[data-testid="image"]'
);
if
(
!
imgWrap
)
{
return
;
}
e
.
stopPropagation
();
e
.
preventDefault
();
e
.
dataTransfer
.
dropEffect
=
'copy'
;
});
window
.
document
.
addEventListener
(
'drop'
,
e
=>
{
const
target
=
e
.
composedPath
()[
0
];
const
imgWrap
=
target
.
closest
(
'[data-testid="image"]'
);
if
(
!
imgWrap
)
{
return
;
}
e
.
stopPropagation
();
e
.
preventDefault
();
const
files
=
e
.
dataTransfer
.
files
;
dropReplaceImage
(
imgWrap
,
files
);
});
window
.
addEventListener
(
'paste'
,
e
=>
{
const
files
=
e
.
clipboardData
.
files
;
if
(
!
isValidImageList
(
files
)
)
{
return
;
return
;
}
}
[...
gradioApp
().
querySelectorAll
(
'input[type=file][accept="image/x-png,image/gif,image/jpeg"]'
)]
[...
gradioApp
().
querySelectorAll
(
'input[type=file][accept="image/x-png,image/gif,image/jpeg"]'
)]
...
@@ -340,6 +379,8 @@ window.addEventListener('paste', e => {
...
@@ -340,6 +379,8 @@ window.addEventListener('paste', e => {
input
.
files
=
files
;
input
.
files
=
files
;
input
.
dispatchEvent
(
new
Event
(
'change'
))
input
.
dispatchEvent
(
new
Event
(
'change'
))
});
});
[...
gradioApp
().
querySelectorAll
(
'[data-testid="image"]'
)]
.
forEach
(
imgWrap
=>
dropReplaceImage
(
imgWrap
,
files
));
});
});
function
ask_for_style_name
(
_
,
prompt_text
,
negative_prompt_text
)
{
function
ask_for_style_name
(
_
,
prompt_text
,
negative_prompt_text
)
{
...
...
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