Fix undo incorrectly undoing text input (#4114)
Fixes an issue where under certain conditions, the ComfyUI custom undo / redo functions would not run when intended to. When trying to undo an action like deleting several nodes, instead the native browser undo runs - e.g. a textarea gets focus and the last typed text is undone. Clicking outside the text area and typing again just keeps doing the same thing.
This commit is contained in:
parent
8328a2d8cd
commit
b6779d8df3
|
@ -105,15 +105,16 @@ export class ChangeTracker {
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
"keydown",
|
"keydown",
|
||||||
(e) => {
|
(e) => {
|
||||||
|
const activeEl = document.activeElement;
|
||||||
requestAnimationFrame(async () => {
|
requestAnimationFrame(async () => {
|
||||||
let activeEl;
|
let bindInputEl;
|
||||||
// If we are auto queue in change mode then we do want to trigger on inputs
|
// If we are auto queue in change mode then we do want to trigger on inputs
|
||||||
if (!app.ui.autoQueueEnabled || app.ui.autoQueueMode === "instant") {
|
if (!app.ui.autoQueueEnabled || app.ui.autoQueueMode === "instant") {
|
||||||
activeEl = document.activeElement;
|
|
||||||
if (activeEl?.tagName === "INPUT" || activeEl?.["type"] === "textarea") {
|
if (activeEl?.tagName === "INPUT" || activeEl?.["type"] === "textarea") {
|
||||||
// Ignore events on inputs, they have their native history
|
// Ignore events on inputs, they have their native history
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
bindInputEl = activeEl;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyIgnored = e.key === "Control" || e.key === "Shift" || e.key === "Alt" || e.key === "Meta";
|
keyIgnored = e.key === "Control" || e.key === "Shift" || e.key === "Alt" || e.key === "Meta";
|
||||||
|
@ -123,7 +124,7 @@ export class ChangeTracker {
|
||||||
if (await changeTracker().undoRedo(e)) return;
|
if (await changeTracker().undoRedo(e)) return;
|
||||||
|
|
||||||
// If our active element is some type of input then handle changes after they're done
|
// If our active element is some type of input then handle changes after they're done
|
||||||
if (ChangeTracker.bindInput(activeEl)) return;
|
if (ChangeTracker.bindInput(bindInputEl)) return;
|
||||||
changeTracker().checkState();
|
changeTracker().checkState();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue