Skip to content

Commit 206de1a

Browse files
Merge pull request #14296 from akx/paste-resolution
Allow pasting in WIDTHxHEIGHT strings into the width/height fields
2 parents b943eeb + 89cfbc3 commit 206de1a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

javascript/ui.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,33 @@ function restoreProgressImg2img() {
215215
}
216216

217217

218+
/**
219+
* Configure the width and height elements on `tabname` to accept
220+
* pasting of resolutions in the form of "width x height".
221+
*/
222+
function setupResolutionPasting(tabname) {
223+
var width = gradioApp().querySelector(`#${tabname}_width input[type=number]`);
224+
var height = gradioApp().querySelector(`#${tabname}_height input[type=number]`);
225+
for (const el of [width, height]) {
226+
el.addEventListener('paste', function(event) {
227+
var pasteData = event.clipboardData.getData('text/plain');
228+
var parsed = pasteData.match(/^\s*(\d+)\D+(\d+)\s*$/);
229+
if (parsed) {
230+
width.value = parsed[1];
231+
height.value = parsed[2];
232+
updateInput(width);
233+
updateInput(height);
234+
event.preventDefault();
235+
}
236+
});
237+
}
238+
}
239+
218240
onUiLoaded(function() {
219241
showRestoreProgressButton('txt2img', localGet("txt2img_task_id"));
220242
showRestoreProgressButton('img2img', localGet("img2img_task_id"));
243+
setupResolutionPasting('txt2img');
244+
setupResolutionPasting('img2img');
221245
});
222246

223247

0 commit comments

Comments
 (0)