Skip to content

Commit 6547af4

Browse files
committed
feat: add default keybindings for changing the mask brush size
Make it easier to change the mask brush size. These keybindings are familiar to users of other image editors.
1 parent 1d06b4d commit 6547af4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/extensions/core/maskeditor.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5382,14 +5382,18 @@ class KeyboardManager {
53825382
if (!this.keysDown.includes(event.key)) {
53835383
this.keysDown.push(event.key)
53845384
}
5385+
const key = event.key.toUpperCase()
53855386
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
5386-
const key = event.key.toUpperCase()
53875387
// Redo: Ctrl + Y, or Ctrl + Shift + Z
53885388
if ((key === 'Y' && !event.shiftKey) || (key == 'Z' && event.shiftKey)) {
53895389
this.messageBroker.publish('redo')
53905390
} else if (key === 'Z' && !event.shiftKey) {
53915391
this.messageBroker.publish('undo')
53925392
}
5393+
} else if (key == '[' && !event.shiftKey) {
5394+
adjustBrushSize(-4)
5395+
} else if (key == ']' && !event.shiftKey) {
5396+
adjustBrushSize(4)
53935397
}
53945398
}
53955399

@@ -5505,13 +5509,17 @@ app.registerExtension({
55055509
id: 'Comfy.MaskEditor.BrushSize.Increase',
55065510
icon: 'pi pi-plus-circle',
55075511
label: 'Increase Brush Size in MaskEditor',
5508-
function: () => changeBrushSize((old) => _.clamp(old + 4, 1, 100))
5512+
function: () => {
5513+
adjustBrushSize(4)
5514+
}
55095515
},
55105516
{
55115517
id: 'Comfy.MaskEditor.BrushSize.Decrease',
55125518
icon: 'pi pi-minus-circle',
55135519
label: 'Decrease Brush Size in MaskEditor',
5514-
function: () => changeBrushSize((old) => _.clamp(old - 4, 1, 100))
5520+
function: () => {
5521+
adjustBrushSize(-4)
5522+
}
55155523
}
55165524
],
55175525
init() {
@@ -5526,6 +5534,10 @@ app.registerExtension({
55265534
}
55275535
})
55285536

5537+
const adjustBrushSize = async (amount: number) => {
5538+
changeBrushSize((oid) => _.clamp(oid + amount, 1, 100))
5539+
}
5540+
55295541
const changeBrushSize = async (sizeChanger: (oldSize: number) => number) => {
55305542
if (!isOpened()) return
55315543
const maskEditor = MaskEditorDialog.getInstance()

0 commit comments

Comments
 (0)