Skip to content

Commit 7dae2eb

Browse files
huchenleigithub-actions
andauthored
Fix clipboard (#100)
* Fix clipboard * Add clipboard tests * Update test expectations [skip ci] --------- Co-authored-by: github-actions <[email protected]>
1 parent 525adb7 commit 7dae2eb

9 files changed

+89
-6
lines changed

browser_tests/ComfyPage.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ export class ComfyPage {
149149
await this.nextFrame();
150150
}
151151

152+
async clickEmptyLatentNode() {
153+
await this.canvas.click({
154+
position: {
155+
x: 724,
156+
y: 625
157+
},
158+
});
159+
this.page.mouse.move(10, 10);
160+
await this.nextFrame();
161+
}
162+
152163
async rightClickEmptyLatentNode() {
153164
await this.canvas.click({
154165
position: {
@@ -169,6 +180,20 @@ export class ComfyPage {
169180
await this.page.keyboard.up('Control');
170181
await this.nextFrame();
171182
}
183+
184+
async ctrlC() {
185+
await this.page.keyboard.down('Control');
186+
await this.page.keyboard.press('KeyC');
187+
await this.page.keyboard.up('Control');
188+
await this.nextFrame();
189+
}
190+
191+
async ctrlV() {
192+
await this.page.keyboard.down('Control');
193+
await this.page.keyboard.press('KeyV');
194+
await this.page.keyboard.up('Control');
195+
await this.nextFrame();
196+
}
172197
}
173198

174199
export const comfyPageFixture = base.extend<{ comfyPage: ComfyPage }>({

browser_tests/copyPaste.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { expect } from "@playwright/test";
2+
import { comfyPageFixture as test } from "./ComfyPage";
3+
4+
test.describe("Copy Paste", () => {
5+
test("Can copy and paste node", async ({ comfyPage }) => {
6+
await comfyPage.clickEmptyLatentNode();
7+
await comfyPage.page.mouse.move(10, 10);
8+
await comfyPage.ctrlC();
9+
await comfyPage.ctrlV();
10+
await expect(comfyPage.canvas).toHaveScreenshot("copied-node.png");
11+
});
12+
13+
test("Can copy and paste text", async ({ comfyPage }) => {
14+
const textBox = comfyPage.widgetTextBox;
15+
await textBox.click();
16+
const originalString = await textBox.inputValue();
17+
await textBox.selectText();
18+
await comfyPage.ctrlC();
19+
await comfyPage.ctrlV();
20+
await comfyPage.ctrlV();
21+
const resultString = await textBox.inputValue();
22+
expect(resultString).toBe(originalString + originalString);
23+
});
24+
25+
/**
26+
* https://github.com/Comfy-Org/ComfyUI_frontend/issues/98
27+
*/
28+
test("Paste in text area with node previously copied", async ({
29+
comfyPage,
30+
}) => {
31+
await comfyPage.clickEmptyLatentNode();
32+
await comfyPage.ctrlC();
33+
const textBox = comfyPage.widgetTextBox;
34+
await textBox.click();
35+
await textBox.inputValue();
36+
await textBox.selectText();
37+
await comfyPage.ctrlC();
38+
await comfyPage.ctrlV();
39+
await comfyPage.ctrlV();
40+
await expect(comfyPage.canvas).toHaveScreenshot(
41+
"paste-in-text-area-with-node-previously-copied.png"
42+
);
43+
});
44+
45+
test("Copy text area does not copy node", async ({ comfyPage }) => {
46+
const textBox = comfyPage.widgetTextBox;
47+
await textBox.click();
48+
await textBox.inputValue();
49+
await textBox.selectText();
50+
await comfyPage.ctrlC();
51+
// Unfocus textbox.
52+
await comfyPage.page.mouse.click(10, 10);
53+
await comfyPage.ctrlV();
54+
await expect(comfyPage.canvas).toHaveScreenshot("no-node-copied.png");
55+
});
56+
});
103 KB
Loading
96.8 KB
Loading
96.5 KB
Loading
90.5 KB
Loading
101 KB
Loading
94.7 KB
Loading

src/scripts/app.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,9 @@ export class ComfyApp {
11151115
await this.loadGraphData(workflow);
11161116
} else {
11171117
if (
1118-
e.target instanceof HTMLInputElement &&
1119-
(e.target.type === "text" || e.target.type === "textarea")
1118+
(e.target instanceof HTMLTextAreaElement &&
1119+
e.target.type === "textarea") ||
1120+
(e.target instanceof HTMLInputElement && e.target.type === "text")
11201121
) {
11211122
return;
11221123
}
@@ -1133,16 +1134,17 @@ export class ComfyApp {
11331134
#addCopyHandler() {
11341135
document.addEventListener("copy", (e) => {
11351136
if (
1136-
e.target instanceof HTMLInputElement &&
1137-
(e.target.type === "text" || e.target.type === "textarea")
1137+
(e.target instanceof HTMLTextAreaElement &&
1138+
e.target.type === "textarea") ||
1139+
(e.target instanceof HTMLInputElement && e.target.type === "text")
11381140
) {
11391141
// Default system copy
11401142
return;
11411143
}
11421144

11431145
// copy nodes and clear clipboard
11441146
if (
1145-
e.target instanceof HTMLElement &&
1147+
e.target instanceof Element &&
11461148
e.target.className === "litegraph" &&
11471149
this.canvas.selected_nodes
11481150
) {
@@ -1269,7 +1271,7 @@ export class ComfyApp {
12691271

12701272
var block_default = false;
12711273

1272-
if (e.target instanceof HTMLElement && e.target.localName == "input") {
1274+
if (e.target instanceof Element && e.target.localName == "input") {
12731275
return;
12741276
}
12751277

0 commit comments

Comments
 (0)