Skip to content

Commit

Permalink
Merge pull request #14296 from akx/paste-resolution
Browse files Browse the repository at this point in the history
Allow pasting in WIDTHxHEIGHT strings into the width/height fields
  • Loading branch information
AUTOMATIC1111 committed Dec 14, 2023
1 parent 6ef0ff3 commit c7cd9b4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,33 @@ function restoreProgressImg2img() {
}


/**
* Configure the width and height elements on `tabname` to accept
* pasting of resolutions in the form of "width x height".
*/
function setupResolutionPasting(tabname) {
var width = gradioApp().querySelector(`#${tabname}_width input[type=number]`);
var height = gradioApp().querySelector(`#${tabname}_height input[type=number]`);
for (const el of [width, height]) {
el.addEventListener('paste', function(event) {
var pasteData = event.clipboardData.getData('text/plain');
var parsed = pasteData.match(/^\s*(\d+)\D+(\d+)\s*$/);
if (parsed) {
width.value = parsed[1];
height.value = parsed[2];
updateInput(width);
updateInput(height);
event.preventDefault();
}
});
}
}

onUiLoaded(function() {
showRestoreProgressButton('txt2img', localGet("txt2img_task_id"));
showRestoreProgressButton('img2img', localGet("img2img_task_id"));
setupResolutionPasting('txt2img');
setupResolutionPasting('img2img');
});


Expand Down

1 comment on commit c7cd9b4

@konung74
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сканирование0001

Please sign in to comment.