Skip to content

Commit bd0bf03

Browse files
Merge pull request #20375 from calixteman/fix_color_copy_paste
[Editor] Make sure the color picker has the right color when pasting an editor
2 parents bc9d34b + 97fec3a commit bd0bf03

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/display/editor/color_picker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ class BasicColorPicker {
334334
if (this.#input) {
335335
return this.#input;
336336
}
337-
const { editorType, colorType, colorValue } = this.#editor;
337+
const { editorType, colorType, color } = this.#editor;
338338
const input = (this.#input = document.createElement("input"));
339339
input.type = "color";
340-
input.value = colorValue || "#000000";
340+
input.value = color || "#000000";
341341
input.className = "basicColorPicker";
342342
input.tabIndex = 0;
343343
input.setAttribute("data-l10n-id", BasicColorPicker.#l10nColor[editorType]);

test/integration/freetext_editor_spec.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,58 @@ describe("FreeText Editor", () => {
181181
}
182182
});
183183

184+
it("must copy/paste and check color", async () => {
185+
// Run sequentially to avoid clipboard issues.
186+
for (const [browserName, page] of pages) {
187+
await switchToFreeText(page);
188+
189+
const rect = await getRect(page, ".annotationEditorLayer");
190+
const firstEditorSelector = getEditorSelector(0);
191+
const data = "Hello PDF.js World !!";
192+
await page.mouse.click(rect.x + 100, rect.y + 100);
193+
await page.waitForSelector(firstEditorSelector, { visible: true });
194+
await page.type(`${firstEditorSelector} .internal`, data);
195+
await commit(page);
196+
await waitForStorageEntries(page, 1);
197+
198+
await page.evaluate(() => {
199+
window.PDFViewerApplication.eventBus.dispatch(
200+
"switchannotationeditorparams",
201+
{
202+
source: null,
203+
type: window.pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
204+
value: "#FF0000",
205+
}
206+
);
207+
});
208+
209+
await selectEditor(page, firstEditorSelector);
210+
await copy(page);
211+
await paste(page);
212+
const secondEditorSelector = getEditorSelector(1);
213+
await page.waitForSelector(secondEditorSelector, { visible: true });
214+
await waitForStorageEntries(page, 2);
215+
216+
const color = await page.$eval(
217+
`${secondEditorSelector} .internal`,
218+
el => getComputedStyle(el).color
219+
);
220+
expect(color)
221+
.withContext(`In ${browserName}`)
222+
.toEqual("rgb(255, 0, 0)");
223+
224+
const inputSelector = `${secondEditorSelector} .basicColorPicker`;
225+
await page.waitForSelector(inputSelector, { visible: true });
226+
227+
const buttonColor = await page.evaluate(sel => {
228+
const input = document.querySelector(sel);
229+
return input.value;
230+
}, inputSelector);
231+
232+
expect(buttonColor).withContext(`In ${browserName}`).toEqual("#ff0000");
233+
}
234+
});
235+
184236
it("must clear all", async () => {
185237
await Promise.all(
186238
pages.map(async ([browserName, page]) => {

0 commit comments

Comments
 (0)