refactor: inject KeyboardHelper into ClipboardHelper

Remove duplicated nextFrame and ctrlSend methods from ClipboardHelper
by delegating to KeyboardHelper instead.

Amp-Thread-ID: https://ampcode.com/threads/T-019c15b9-efed-72eb-b092-1e92a11f44e3
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-01-31 12:33:38 -08:00
parent 98c90d16a0
commit 5b6d1f5bdb
2 changed files with 7 additions and 18 deletions

View File

@@ -223,7 +223,7 @@ export class ComfyPage {
this.nodeOps = new NodeOperationsHelper(this)
this.settings = new SettingsHelper(page)
this.keyboard = new KeyboardHelper(page, this.canvas)
this.clipboard = new ClipboardHelper(page, this.canvas)
this.clipboard = new ClipboardHelper(this.keyboard, this.canvas)
this.workflow = new WorkflowHelper(this)
this.contextMenu = new ContextMenu(page)
}

View File

@@ -1,29 +1,18 @@
import type { Locator, Page } from '@playwright/test'
import type { Locator } from '@playwright/test'
import type { KeyboardHelper } from './KeyboardHelper'
export class ClipboardHelper {
constructor(
private readonly page: Page,
private readonly keyboard: KeyboardHelper,
private readonly canvas: Locator
) {}
private async nextFrame(): Promise<void> {
await this.page.evaluate(() => new Promise<number>(requestAnimationFrame))
}
private async ctrlSend(
keyToPress: string,
locator: Locator | null = this.canvas
): Promise<void> {
const target = locator ?? this.page.keyboard
await target.press(`Control+${keyToPress}`)
await this.nextFrame()
}
async copy(locator?: Locator | null): Promise<void> {
await this.ctrlSend('KeyC', locator ?? this.canvas)
await this.keyboard.ctrlSend('KeyC', locator ?? this.canvas)
}
async paste(locator?: Locator | null): Promise<void> {
await this.ctrlSend('KeyV', locator ?? this.canvas)
await this.keyboard.ctrlSend('KeyV', locator ?? this.canvas)
}
}