From 468056958b63cb869d627746b5b5a1c629fd7548 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Mon, 22 May 2023 20:46:25 -0600 Subject: [PATCH 1/3] Add reorder hotkeys Shifts selected items with ctrl+left/right --- javascript/edit-order.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 javascript/edit-order.js diff --git a/javascript/edit-order.js b/javascript/edit-order.js new file mode 100644 index 00000000..e924d419 --- /dev/null +++ b/javascript/edit-order.js @@ -0,0 +1,36 @@ +function keyupEditOrder(event){ + let target = event.originalTarget || event.composedPath()[0]; + if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return; + if (!event.metaKey && !event.ctrlKey) return; + + let isLeft = event.key == "ArrowLeft" + let isRight = event.key == "ArrowRight" + if (!isLeft && !isRight) return; + + let selectionStart = target.selectionStart; + let selectionEnd = target.selectionEnd; + let text = target.value; + let items = text.split(",") + let indexStart = (text.slice(0, selectionStart).match(/,/g) || []).length + let indexEnd = (text.slice(0, selectionEnd).match(/,/g) || []).length + let range = indexEnd - indexStart + 1 + + if (isLeft && indexStart > 0) { + items.splice(indexStart - 1, 0, ...items.splice(indexStart, range)) + target.value = items.join() + target.selectionStart = items.slice(0, indexStart - 1).join().length + (indexStart == 1 ? 0 : 1) + target.selectionEnd = items.slice(0, indexEnd).join().length + } else if (isRight && indexEnd < items.length - 1) { + items.splice(indexStart + 1, 0, ...items.splice(indexStart, range)) + target.value = items.join() + target.selectionStart = items.slice(0, indexStart + 1).join().length + 1 + target.selectionEnd = items.slice(0, indexEnd + 2).join().length + } + + event.preventDefault() + updateInput(target) +} + +addEventListener('keydown', (event) => { + keyupEditOrder(event); +}); From dafe5193633e4ab27aad74de63ea5fcc3d31aba8 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Mon, 22 May 2023 21:23:39 -0600 Subject: [PATCH 2/3] Fix lint errors --- javascript/edit-order.js | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/javascript/edit-order.js b/javascript/edit-order.js index e924d419..11703350 100644 --- a/javascript/edit-order.js +++ b/javascript/edit-order.js @@ -1,34 +1,34 @@ -function keyupEditOrder(event){ - let target = event.originalTarget || event.composedPath()[0]; - if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return; - if (!event.metaKey && !event.ctrlKey) return; +function keyupEditOrder(event) { + let target = event.originalTarget || event.composedPath()[0]; + if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return; + if (!event.metaKey && !event.ctrlKey) return; - let isLeft = event.key == "ArrowLeft" - let isRight = event.key == "ArrowRight" - if (!isLeft && !isRight) return; + let isLeft = event.key == "ArrowLeft"; + let isRight = event.key == "ArrowRight"; + if (!isLeft && !isRight) return; - let selectionStart = target.selectionStart; - let selectionEnd = target.selectionEnd; - let text = target.value; - let items = text.split(",") - let indexStart = (text.slice(0, selectionStart).match(/,/g) || []).length - let indexEnd = (text.slice(0, selectionEnd).match(/,/g) || []).length - let range = indexEnd - indexStart + 1 + let selectionStart = target.selectionStart; + let selectionEnd = target.selectionEnd; + let text = target.value; + let items = text.split(","); + let indexStart = (text.slice(0, selectionStart).match(/,/g) || []).length; + let indexEnd = (text.slice(0, selectionEnd).match(/,/g) || []).length; + let range = indexEnd - indexStart + 1; if (isLeft && indexStart > 0) { - items.splice(indexStart - 1, 0, ...items.splice(indexStart, range)) - target.value = items.join() - target.selectionStart = items.slice(0, indexStart - 1).join().length + (indexStart == 1 ? 0 : 1) - target.selectionEnd = items.slice(0, indexEnd).join().length + items.splice(indexStart - 1, 0, ...items.splice(indexStart, range)); + target.value = items.join(); + target.selectionStart = items.slice(0, indexStart - 1).join().length + (indexStart == 1 ? 0 : 1); + target.selectionEnd = items.slice(0, indexEnd).join().length; } else if (isRight && indexEnd < items.length - 1) { - items.splice(indexStart + 1, 0, ...items.splice(indexStart, range)) - target.value = items.join() - target.selectionStart = items.slice(0, indexStart + 1).join().length + 1 - target.selectionEnd = items.slice(0, indexEnd + 2).join().length + items.splice(indexStart + 1, 0, ...items.splice(indexStart, range)); + target.value = items.join(); + target.selectionStart = items.slice(0, indexStart + 1).join().length + 1; + target.selectionEnd = items.slice(0, indexEnd + 2).join().length; } - - event.preventDefault() - updateInput(target) + + event.preventDefault(); + updateInput(target); } addEventListener('keydown', (event) => { From 43bdaa2f0eda79c685792b06a2bd84c65806a48f Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Thu, 25 May 2023 18:49:28 -0600 Subject: [PATCH 3/3] Make ctrl+left/right optional --- javascript/edit-order.js | 1 + modules/shared.py | 1 + 2 files changed, 2 insertions(+) diff --git a/javascript/edit-order.js b/javascript/edit-order.js index 11703350..50f7fe37 100644 --- a/javascript/edit-order.js +++ b/javascript/edit-order.js @@ -1,4 +1,5 @@ function keyupEditOrder(event) { + if (!opts.keyedit_move) return; let target = event.originalTarget || event.composedPath()[0]; if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return; if (!event.metaKey && !event.ctrlKey) return; diff --git a/modules/shared.py b/modules/shared.py index b3508883..280c4451 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -405,6 +405,7 @@ options_templates.update(options_section(('ui', "User interface"), { "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}), "keyedit_precision_extra": OptionInfo(0.05, "Ctrl+up/down precision when editing ", gr.Slider, {"minimum": 0.01, "maximum": 0.2, "step": 0.001}), "keyedit_delimiters": OptionInfo(".,\\/!?%^*;:{}=`~()", "Ctrl+up/down word delimiters"), + "keyedit_move": OptionInfo(False, "Ctrl+left/right moves prompt elements"), "quicksettings_list": OptionInfo(["sd_model_checkpoint"], "Quicksettings list", ui_components.DropdownMulti, lambda: {"choices": list(opts.data_labels.keys())}), "hidden_tabs": OptionInfo([], "Hidden UI tabs (requires restart)", ui_components.DropdownMulti, lambda: {"choices": [x for x in tab_names]}), "ui_reorder": OptionInfo(", ".join(ui_reorder_categories), "txt2img/img2img UI item order"),