Skip to content

Commit d2f8e60

Browse files
authored
Merge pull request #20098 from calixteman/update_highlight_color
[Editor] Make possible to change the highlight color from the main panel
2 parents ef92920 + 5162209 commit d2f8e60

6 files changed

Lines changed: 47 additions & 15 deletions

File tree

src/display/editor/color_picker.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class ColorPicker {
4343

4444
#uiManager = null;
4545

46-
#type;
47-
4846
static #l10nColor = null;
4947

5048
static get _keyboardManager() {
@@ -74,11 +72,9 @@ class ColorPicker {
7472
constructor({ editor = null, uiManager = null }) {
7573
if (editor) {
7674
this.#isMainColorPicker = false;
77-
this.#type = AnnotationEditorParamsType.HIGHLIGHT_COLOR;
7875
this.#editor = editor;
7976
} else {
8077
this.#isMainColorPicker = true;
81-
this.#type = AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR;
8278
}
8379
this.#uiManager = editor?._uiManager || uiManager;
8480
this.#eventBus = this.#uiManager._eventBus;
@@ -163,9 +159,10 @@ class ColorPicker {
163159
event.stopPropagation();
164160
this.#eventBus.dispatch("switchannotationeditorparams", {
165161
source: this,
166-
type: this.#type,
162+
type: AnnotationEditorParamsType.HIGHLIGHT_COLOR,
167163
value: color,
168164
});
165+
this.updateColor(color);
169166
}
170167

171168
_colorSelectFromKeyboard(event) {

src/display/editor/highlight.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class HighlightEditor extends AnnotationEditor {
278278
/** @inheritdoc */
279279
static updateDefaultParams(type, value) {
280280
switch (type) {
281-
case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
281+
case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
282282
HighlightEditor._defaultColor = value;
283283
break;
284284
case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
@@ -310,7 +310,7 @@ class HighlightEditor extends AnnotationEditor {
310310
static get defaultPropertiesToUpdate() {
311311
return [
312312
[
313-
AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR,
313+
AnnotationEditorParamsType.HIGHLIGHT_COLOR,
314314
HighlightEditor._defaultColor,
315315
],
316316
[

src/display/editor/tools.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,9 +1786,6 @@ class AnnotationEditorUIManager {
17861786
case AnnotationEditorParamsType.CREATE:
17871787
this.currentLayer.addNewEditor(value);
17881788
return;
1789-
case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
1790-
this.#mainHighlightColorPicker?.updateColor(value);
1791-
break;
17921789
case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
17931790
this._eventBus.dispatch("reporttelemetry", {
17941791
source: this,

src/shared/util.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ const AnnotationEditorParamsType = {
8888
INK_THICKNESS: 22,
8989
INK_OPACITY: 23,
9090
HIGHLIGHT_COLOR: 31,
91-
HIGHLIGHT_DEFAULT_COLOR: 32,
92-
HIGHLIGHT_THICKNESS: 33,
93-
HIGHLIGHT_FREE: 34,
94-
HIGHLIGHT_SHOW_ALL: 35,
91+
HIGHLIGHT_THICKNESS: 32,
92+
HIGHLIGHT_FREE: 33,
93+
HIGHLIGHT_SHOW_ALL: 34,
9594
DRAW_STEP: 41,
9695
};
9796

test/integration/highlight_editor_spec.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,4 +2710,43 @@ describe("Highlight Editor", () => {
27102710
);
27112711
});
27122712
});
2713+
2714+
describe("Highlight must change their color when selected", () => {
2715+
let pages;
2716+
2717+
beforeEach(async () => {
2718+
pages = await loadAndWait(
2719+
"tracemonkey.pdf",
2720+
".annotationEditorLayer",
2721+
null,
2722+
null,
2723+
{ highlightEditorColors: "red=#AB0000,blue=#0000AB" }
2724+
);
2725+
});
2726+
2727+
afterEach(async () => {
2728+
await closePages(pages);
2729+
});
2730+
2731+
it("must check that the color is correctly updated", async () => {
2732+
await Promise.all(
2733+
pages.map(async ([browserName, page]) => {
2734+
await switchToHighlight(page);
2735+
2736+
const rect = await getSpanRectFromText(page, 1, "Abstract");
2737+
const x = rect.x + rect.width / 2;
2738+
const y = rect.y + rect.height / 2;
2739+
await page.mouse.click(x, y, { count: 2, delay: 100 });
2740+
const highlightSelector = `.page[data-page-number = "1"] .canvasWrapper > svg.highlight`;
2741+
await page.waitForSelector(`${highlightSelector}[fill = "#AB0000"]`);
2742+
2743+
await page.click(
2744+
"#editorHighlightColorPicker button[title = 'Blue']"
2745+
);
2746+
2747+
await page.waitForSelector(`${highlightSelector}[fill = "#0000AB"]`);
2748+
})
2749+
);
2750+
});
2751+
});
27132752
});

web/annotation_editor_params.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class AnnotationEditorParams {
118118
case AnnotationEditorParamsType.INK_OPACITY:
119119
editorInkOpacity.value = value;
120120
break;
121-
case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
121+
case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
122122
eventBus.dispatch("mainhighlightcolorpickerupdatecolor", {
123123
source: this,
124124
value,

0 commit comments

Comments
 (0)