Skip to content

Commit 3e3e909

Browse files
authored
Fix "undo" incorrectly undoing text input (#247)
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 textarea and hitting ctrl + z again just keeps doing the same thing.
1 parent e128f39 commit 3e3e909

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/scripts/changeTracker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ export class ChangeTracker {
110110
window.addEventListener(
111111
'keydown',
112112
(e) => {
113+
const activeEl = document.activeElement;
113114
requestAnimationFrame(async () => {
114-
let activeEl
115+
let bindInputEl
115116
// If we are auto queue in change mode then we do want to trigger on inputs
116117
if (!app.ui.autoQueueEnabled || app.ui.autoQueueMode === 'instant') {
117-
activeEl = document.activeElement
118118
if (
119119
activeEl?.tagName === 'INPUT' ||
120120
activeEl?.['type'] === 'textarea'
121121
) {
122122
// Ignore events on inputs, they have their native history
123123
return
124124
}
125+
bindInputEl = activeEl
125126
}
126127

127128
keyIgnored =
@@ -135,7 +136,7 @@ export class ChangeTracker {
135136
if (await changeTracker().undoRedo(e)) return
136137

137138
// If our active element is some type of input then handle changes after they're done
138-
if (ChangeTracker.bindInput(app, activeEl)) return
139+
if (ChangeTracker.bindInput(app, bindInputEl)) return
139140
changeTracker().checkState()
140141
})
141142
},

0 commit comments

Comments
 (0)