Skip to content

Commit

Permalink
Merge pull request #19174 from calixteman/ink_update_width
Browse files Browse the repository at this point in the history
[Editor] Correctly update the current drawing when zooming
  • Loading branch information
calixteman authored Dec 5, 2024
2 parents 28d801e + dfa0e79 commit f180de4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ class AnnotationEditorLayer {
return;
}

this.#uiManager.unselectAll();
this.#uiManager.setCurrentDrawingSession(this);
this.#drawingAC = new AbortController();
const signal = this.#uiManager.combinedSignal(this.#drawingAC);
this.div.addEventListener(
Expand All @@ -816,17 +816,16 @@ class AnnotationEditorLayer {
},
{ signal }
);
this.#uiManager.disableUserSelect(true);
this.#currentEditorType.startDrawing(this, this.#uiManager, false, event);
}

endDrawingSession(isAborted = false) {
if (!this.#drawingAC) {
return null;
}
this.#uiManager.setCurrentDrawingSession(null);
this.#drawingAC.abort();
this.#drawingAC = null;
this.#uiManager.disableUserSelect(false);
return this.#currentEditorType.endDrawing(isAborted);
}

Expand Down
22 changes: 19 additions & 3 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ class AnnotationEditorUIManager {

#copyPasteAC = null;

#currentDrawingSession = null;

#currentPageIndex = 0;

#deletedAnnotationsElementIds = new Set();
Expand Down Expand Up @@ -972,6 +974,20 @@ class AnnotationEditorUIManager {
);
}

/**
* Set the current drawing session.
* @param {AnnotationEditorLayer} layer
*/
setCurrentDrawingSession(layer) {
if (layer) {
this.unselectAll();
this.disableUserSelect(true);
} else {
this.disableUserSelect(false);
}
this.#currentDrawingSession = layer;
}

setMainHighlightColorPicker(colorPicker) {
this.#mainHighlightColorPicker = colorPicker;
}
Expand Down Expand Up @@ -1054,7 +1070,7 @@ class AnnotationEditorUIManager {
for (const editor of this.#editorsToRescale) {
editor.onScaleChanging();
}
this.currentLayer?.onScaleChanging();
this.#currentDrawingSession?.onScaleChanging();
}

onRotationChanging({ pagesRotation }) {
Expand Down Expand Up @@ -1984,7 +2000,7 @@ class AnnotationEditorUIManager {
* @param {AnnotationEditor} editor
*/
setSelected(editor) {
this.currentLayer?.commitOrRemove();
this.#currentDrawingSession?.commitOrRemove();
for (const ed of this.#selectedEditors) {
if (ed !== editor) {
ed.unselect();
Expand Down Expand Up @@ -2176,7 +2192,7 @@ class AnnotationEditorUIManager {
}
}

if (this.currentLayer?.commitOrRemove()) {
if (this.#currentDrawingSession?.commitOrRemove()) {
return;
}

Expand Down
62 changes: 62 additions & 0 deletions test/integration/ink_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,66 @@ describe("Ink Editor", () => {
);
});
});

describe("Ink must update its stroke width when not the current active layer", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
});

afterAll(async () => {
await closePages(pages);
});

it("must check that the stroke width has been updated after zooming", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToInk(page);

const rect = await getRect(page, ".annotationEditorLayer");

const x = rect.x + 20;
const y = rect.y + 20;
const clickHandle = await waitForPointerUp(page);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + 50, y + 50);
await page.mouse.up();
await awaitPromise(clickHandle);

const svgSelector = ".canvasWrapper svg.draw";
const strokeWidth = await page.$eval(svgSelector, el =>
parseFloat(el.getAttribute("stroke-width"))
);

await scrollIntoView(page, `.page[data-page-number = "2"]`);

const rectPageTwo = await getRect(
page,
`.page[data-page-number = "2"] .annotationEditorLayer`
);
const originX = rectPageTwo.x + rectPageTwo.width / 2;
const originY = rectPageTwo.y + rectPageTwo.height / 2;
await page.evaluate(
origin => {
window.PDFViewerApplication.pdfViewer.increaseScale({
scaleFactor: 1.5,
origin,
});
},
[originX, originY]
);

const newStrokeWidth = await page.$eval(svgSelector, el =>
parseFloat(el.getAttribute("stroke-width"))
);

expect(newStrokeWidth)
.withContext(`In ${browserName}`)
.not.toEqual(strokeWidth);
})
);
});
});
});

0 comments on commit f180de4

Please sign in to comment.