Refactor ExcalidrawElement (#874)

* Get rid of isSelected, canvas, canvasZoom, canvasOffsetX and canvasOffsetY on ExcalidrawElement.

* Fix most unit tests. Fix cmd a. Fix alt drag

* Focus on paste

* shift select should include previously selected items

* Fix last test

* Move this.shape out of ExcalidrawElement and into a WeakMap
This commit is contained in:
Pete Hunt 2020-03-08 10:20:55 -07:00 committed by GitHub
parent 8ecb4201db
commit ccbbdb75a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 416 additions and 306 deletions

View file

@ -31,7 +31,7 @@ describe("move element", () => {
expect(renderScene).toHaveBeenCalledTimes(4);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
renderScene.mockClear();
@ -64,7 +64,7 @@ describe("duplicate element on move when ALT is clicked", () => {
expect(renderScene).toHaveBeenCalledTimes(4);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
renderScene.mockClear();
@ -77,6 +77,7 @@ describe("duplicate element on move when ALT is clicked", () => {
expect(renderScene).toHaveBeenCalledTimes(3);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(2);
// previous element should stay intact
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
expect([h.elements[1].x, h.elements[1].y]).toEqual([0, 40]);

View file

@ -31,7 +31,7 @@ describe("resize element", () => {
expect(renderScene).toHaveBeenCalledTimes(4);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
expect([h.elements[0].width, h.elements[0].height]).toEqual([30, 50]);
@ -72,7 +72,7 @@ describe("resize element with aspect ratio when SHIFT is clicked", () => {
expect(renderScene).toHaveBeenCalledTimes(4);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
expect([h.elements[0].x, h.elements[0].y]).toEqual([30, 20]);
expect([h.elements[0].width, h.elements[0].height]).toEqual([30, 50]);

View file

@ -97,7 +97,7 @@ describe("select single element on the scene", () => {
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("diamond", () => {
@ -122,7 +122,7 @@ describe("select single element on the scene", () => {
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("ellipse", () => {
@ -147,7 +147,7 @@ describe("select single element on the scene", () => {
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("arrow", () => {
@ -172,7 +172,7 @@ describe("select single element on the scene", () => {
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("arrow", () => {
@ -197,6 +197,6 @@ describe("select single element on the scene", () => {
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.elements[0].isSelected).toBeTruthy();
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
});