Canvas: Undo hotkey

This commit is contained in:
w-e-w
2024-11-20 04:35:45 +09:00
parent 4e808fbef4
commit 356339eff2
2 changed files with 10 additions and 1 deletions
@@ -226,6 +226,7 @@ onUiLoaded(async() => {
canvas_show_tooltip: true,
canvas_auto_expand: true,
canvas_blur_prompt: false,
canvas_hotkey_undo: "KeyZ",
};
const functionMap = {
@@ -321,6 +322,7 @@ onUiLoaded(async() => {
action: "Adjust brush size",
keySuffix: " + wheel"
},
{configKey: "canvas_hotkey_undo", action: "Undo brush stroke"},
{configKey: "canvas_hotkey_reset", action: "Reset zoom"},
{
configKey: "canvas_hotkey_fullscreen",
@@ -489,6 +491,11 @@ onUiLoaded(async() => {
}
}
// Undo the last brush stroke by clicking the undo button
function undoBrushStroke() {
gradioApp().querySelector(`${elemId} button[aria-label='Undo']`).click();
}
// Reset zoom when uploading a new image
const fileInput = gradioApp().querySelector(
`${elemId} input[type="file"][accept="image/*"].svelte-116rqfv`
@@ -708,7 +715,8 @@ onUiLoaded(async() => {
[hotkeysConfig.canvas_hotkey_overlap]: toggleOverlap,
[hotkeysConfig.canvas_hotkey_fullscreen]: fitToScreen,
[hotkeysConfig.canvas_hotkey_shrink_brush]: () => adjustBrushSize(elemId, 10),
[hotkeysConfig.canvas_hotkey_grow_brush]: () => adjustBrushSize(elemId, -10)
[hotkeysConfig.canvas_hotkey_grow_brush]: () => adjustBrushSize(elemId, -10),
[hotkeysConfig.canvas_hotkey_undo]: undoBrushStroke
};
const action = hotkeyActions[event.code];