Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/scripts/changeTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,78 @@ describe('ChangeTracker', () => {
expect(undo).toHaveBeenCalledTimes(undoCalls)
}
)

it.for([
{ editor: 'INPUT', createElement: () => document.createElement('input') },
{
editor: 'TEXTAREA',
createElement: () => document.createElement('textarea')
},
{
editor: 'contenteditable',
createElement: () => {
const element = document.createElement('div')
Object.defineProperty(element, 'isContentEditable', { value: true })
return element
}
}
])(
'leaves $editor history to the editor without scanning modals',
({ createElement }) => {
vi.spyOn(document, 'activeElement', 'get').mockReturnValue(
createElement()
)
useQueueSettingsStore().mode = 'disabled'
const querySelectorAll = vi.spyOn(document, 'querySelectorAll')
const frames: FrameRequestCallback[] = []
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((frame) =>
frames.push(frame)
)
const addEventListener = vi
.spyOn(window, 'addEventListener')
.mockImplementation(() => {})
ChangeTracker.init()
const keydown = addEventListener.mock.calls.find(
([type]) => type === 'keydown'
)?.[1]
if (typeof keydown !== 'function')
throw new Error('keydown listener missing')

keydown(new KeyboardEvent('keydown', { key: 'a' }))

expect(querySelectorAll).not.toHaveBeenCalled()
expect(frames).toHaveLength(0)
}
)

it('captures editor changes when store-backed auto-queue uses change mode', async () => {
const editor = document.createElement('input')
vi.spyOn(document, 'activeElement', 'get').mockReturnValue(editor)
useQueueSettingsStore().mode = 'change'
app.ui.autoQueueEnabled = false
const tracker = createTracker(createState(1))
mockCanvasState(createState(2))
const frames: FrameRequestCallback[] = []
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((frame) =>
frames.push(frame)
)
const addEventListener = vi
.spyOn(window, 'addEventListener')
.mockImplementation(() => {})
ChangeTracker.init()
const keydown = addEventListener.mock.calls.find(
([type]) => type === 'keydown'
)?.[1]
if (typeof keydown !== 'function')
throw new Error('keydown listener missing')

keydown(new KeyboardEvent('keydown', { key: 'a' }))
expect(frames).toHaveLength(1)
await frames[0](0)

expect(dispatchedEventNames()).toContain('autoQueueGraphChanged')
expect(tracker.activeState.nodes).toHaveLength(2)
})
})

describe('captureCanvasState', () => {
Expand Down
22 changes: 13 additions & 9 deletions src/scripts/changeTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,24 +531,28 @@ export class ChangeTracker {
// If the mask editor is opened, we don't want to trigger on key events
const comfyApp = app.constructor as typeof ComfyApp
if (comfyApp.maskeditor_is_opended?.()) return

const activeEl = document.activeElement
if (
!isAutoQueueOnChange() &&
(activeEl?.tagName === 'INPUT' ||
activeEl?.tagName === 'TEXTAREA' ||
(activeEl instanceof HTMLElement && activeEl.isContentEditable))
) {
// Text editors own their history. Bail out before the document-wide
// modal probes, whose cost otherwise scales with transcript size.
return
}
if (isModalOpen(dialogStore.dialogStack.length)) return

// The layer editor has its own session-local undo history
if (useDialogStore().isDialogOpen(LAYER_EDITOR_DIALOG_KEY)) return

const activeEl = document.activeElement
const selectOnlyAtKeydown = isSelectOnly(app.canvas)
requestAnimationFrame(async () => {
let bindInputEl: Element | null = null
// 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 (
activeEl?.tagName === 'INPUT' ||
(activeEl && 'type' in activeEl && activeEl.type === 'textarea')
) {
// Ignore events on inputs, they have their native history
return
}
if (!isAutoQueueOnChange()) {
bindInputEl = activeEl
}

Expand Down
Loading