mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 07:30:11 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user