[Editor] Avoid to slightly move ink editor when undoing/redoing
This commit is contained in:
		
							parent
							
								
									80689c6444
								
							
						
					
					
						commit
						9a464b70c1
					
				@ -162,11 +162,11 @@ class InkEditor extends AnnotationEditor {
 | 
				
			|||||||
    this.parent.addCommands({
 | 
					    this.parent.addCommands({
 | 
				
			||||||
      cmd: () => {
 | 
					      cmd: () => {
 | 
				
			||||||
        this.thickness = thickness;
 | 
					        this.thickness = thickness;
 | 
				
			||||||
        this.#fitToContent(/* thicknessChanged = */ true);
 | 
					        this.#fitToContent();
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      undo: () => {
 | 
					      undo: () => {
 | 
				
			||||||
        this.thickness = savedThickness;
 | 
					        this.thickness = savedThickness;
 | 
				
			||||||
        this.#fitToContent(/* thicknessChanged = */ true);
 | 
					        this.#fitToContent();
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      mustExec: true,
 | 
					      mustExec: true,
 | 
				
			||||||
      type: AnnotationEditorParamsType.INK_THICKNESS,
 | 
					      type: AnnotationEditorParamsType.INK_THICKNESS,
 | 
				
			||||||
@ -478,7 +478,7 @@ class InkEditor extends AnnotationEditor {
 | 
				
			|||||||
    this.#disableEditing = true;
 | 
					    this.#disableEditing = true;
 | 
				
			||||||
    this.div.classList.add("disabled");
 | 
					    this.div.classList.add("disabled");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.#fitToContent();
 | 
					    this.#fitToContent(/* firstTime = */ true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.parent.addInkEditorIfNeeded(/* isCommitting = */ true);
 | 
					    this.parent.addInkEditorIfNeeded(/* isCommitting = */ true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -928,7 +928,7 @@ class InkEditor extends AnnotationEditor {
 | 
				
			|||||||
   * the bounding box of the contents.
 | 
					   * the bounding box of the contents.
 | 
				
			||||||
   * @returns {undefined}
 | 
					   * @returns {undefined}
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  #fitToContent(thicknessChanged = false) {
 | 
					  #fitToContent(firstTime = false) {
 | 
				
			||||||
    if (this.isEmpty()) {
 | 
					    if (this.isEmpty()) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -965,9 +965,7 @@ class InkEditor extends AnnotationEditor {
 | 
				
			|||||||
    this.#realHeight = height;
 | 
					    this.#realHeight = height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.setDims(width, height);
 | 
					    this.setDims(width, height);
 | 
				
			||||||
    const unscaledPadding = thicknessChanged
 | 
					    const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
 | 
				
			||||||
      ? 0
 | 
					 | 
				
			||||||
      : padding / this.scaleFactor / 2;
 | 
					 | 
				
			||||||
    this.translate(
 | 
					    this.translate(
 | 
				
			||||||
      prevTranslationX - this.translationX - unscaledPadding,
 | 
					      prevTranslationX - this.translationX - unscaledPadding,
 | 
				
			||||||
      prevTranslationY - this.translationY - unscaledPadding
 | 
					      prevTranslationY - this.translationY - unscaledPadding
 | 
				
			||||||
 | 
				
			|||||||
@ -74,5 +74,65 @@ describe("Editor", () => {
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it("must draw, undo/redo and check that the editor don't move", async () => {
 | 
				
			||||||
 | 
					      await Promise.all(
 | 
				
			||||||
 | 
					        pages.map(async ([browserName, page]) => {
 | 
				
			||||||
 | 
					          await page.keyboard.down("Control");
 | 
				
			||||||
 | 
					          await page.keyboard.press("a");
 | 
				
			||||||
 | 
					          await page.keyboard.up("Control");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          await page.keyboard.press("Backspace");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const rect = await page.$eval(".annotationEditorLayer", el => {
 | 
				
			||||||
 | 
					            // With Chrome something is wrong when serializing a DomRect,
 | 
				
			||||||
 | 
					            // hence we extract the values and just return them.
 | 
				
			||||||
 | 
					            const { x, y } = el.getBoundingClientRect();
 | 
				
			||||||
 | 
					            return { x, y };
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const xStart = rect.x + 300;
 | 
				
			||||||
 | 
					          const yStart = rect.y + 300;
 | 
				
			||||||
 | 
					          await page.mouse.move(xStart, yStart);
 | 
				
			||||||
 | 
					          await page.mouse.down();
 | 
				
			||||||
 | 
					          await page.mouse.move(xStart + 50, yStart + 50);
 | 
				
			||||||
 | 
					          await page.mouse.up();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          await page.keyboard.press("Escape");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const rectBefore = await page.$eval(".inkEditor canvas", el => {
 | 
				
			||||||
 | 
					            const { x, y } = el.getBoundingClientRect();
 | 
				
			||||||
 | 
					            return { x, y };
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          for (let i = 0; i < 30; i++) {
 | 
				
			||||||
 | 
					            await page.keyboard.down("Control");
 | 
				
			||||||
 | 
					            await page.keyboard.press("z");
 | 
				
			||||||
 | 
					            await page.keyboard.up("Control");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await page.waitForTimeout(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await page.keyboard.down("Control");
 | 
				
			||||||
 | 
					            await page.keyboard.press("y");
 | 
				
			||||||
 | 
					            await page.keyboard.up("Control");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await page.waitForTimeout(10);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const rectAfter = await page.$eval(".inkEditor canvas", el => {
 | 
				
			||||||
 | 
					            const { x, y } = el.getBoundingClientRect();
 | 
				
			||||||
 | 
					            return { x, y };
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          expect(Math.round(rectBefore.x))
 | 
				
			||||||
 | 
					            .withContext(`In ${browserName}`)
 | 
				
			||||||
 | 
					            .toEqual(Math.round(rectAfter.x));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          expect(Math.round(rectBefore.y))
 | 
				
			||||||
 | 
					            .withContext(`In ${browserName}`)
 | 
				
			||||||
 | 
					            .toEqual(Math.round(rectAfter.y));
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user