Skip to content

Commit

Permalink
fix: ignoring keydown when 2nd open
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Dec 4, 2023
1 parent 5904cd9 commit 2c59674
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions web/extensions/core/maskeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class MaskEditorDialog extends ComfyDialog {
this.element.appendChild(bottom_panel);
document.body.appendChild(brush);

var brush_size_slider = this.createLeftSlider(self, "Thickness", (event) => {
this.brush_size_slider = this.createLeftSlider(self, "Thickness", (event) => {
self.brush_size = event.target.value;
self.updateBrushPreview(self, null, null);
});
Expand Down Expand Up @@ -224,7 +224,7 @@ class MaskEditorDialog extends ComfyDialog {
bottom_panel.appendChild(clearButton);
bottom_panel.appendChild(this.saveButton);
bottom_panel.appendChild(cancelButton);
bottom_panel.appendChild(brush_size_slider);
bottom_panel.appendChild(this.brush_size_slider);

imgCanvas.style.position = "absolute";
maskCanvas.style.position = "absolute";
Expand Down Expand Up @@ -280,6 +280,9 @@ class MaskEditorDialog extends ComfyDialog {
observer.observe(this.element, config);
}

// The keydown event needs to be reconfigured when closing the dialog as it gets removed.
document.addEventListener('keydown', MaskEditorDialog.handleKeyDown);

if(ComfyApp.clipspace_return_node) {
this.saveButton.innerText = "Save to node";
}
Expand Down Expand Up @@ -437,7 +440,6 @@ class MaskEditorDialog extends ComfyDialog {
maskCanvas.addEventListener('pointerleave', (event) => { this.brush.style.display = "none"; });

document.addEventListener('pointerup', MaskEditorDialog.handlePointerUp);
document.addEventListener('keydown', MaskEditorDialog.handleKeyDown);

this.handler_registered = true;
}
Expand All @@ -453,8 +455,10 @@ class MaskEditorDialog extends ComfyDialog {
const self = MaskEditorDialog.instance;
if (event.key === ']') {
self.brush_size = Math.min(self.brush_size+2, 100);
self.brush_slider_input.value = self.brush_size;
} else if (event.key === '[') {
self.brush_size = Math.max(self.brush_size-2, 1);
self.brush_slider_input.value = self.brush_size;
} else if(event.key === 'Enter') {
self.save();
}
Expand Down

0 comments on commit 2c59674

Please sign in to comment.