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

@ -1,6 +1,7 @@
import { ExcalidrawElement } from "../element/types";
import { getElementAbsoluteCoords, hitTest } from "../element";
import { AppState } from "../types";
export const hasBackground = (type: string) =>
type === "rectangle" || type === "ellipse" || type === "diamond";
@ -16,6 +17,7 @@ export const hasText = (type: string) => type === "text";
export function getElementAtPosition(
elements: readonly ExcalidrawElement[],
appState: AppState,
x: number,
y: number,
zoom: number,
@ -23,7 +25,7 @@ export function getElementAtPosition(
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
if (hitTest(elements[i], x, y, zoom)) {
if (hitTest(elements[i], appState, x, y, zoom)) {
hitElement = elements[i];
break;
}