diff --git a/src/actions/actionAddToLibrary.ts b/src/actions/actionAddToLibrary.ts index ef69a60d..feb4725e 100644 --- a/src/actions/actionAddToLibrary.ts +++ b/src/actions/actionAddToLibrary.ts @@ -1,6 +1,4 @@ import { register } from "./register"; -import { getSelectedElements } from "../scene"; -import { getNonDeletedElements } from "../element"; import { deepCopyElement } from "../element/newElement"; import { randomId } from "../random"; import { t } from "../i18n"; @@ -9,14 +7,11 @@ export const actionAddToLibrary = register({ name: "addToLibrary", trackEvent: { category: "element" }, perform: (elements, appState, _, app) => { - const selectedElements = getSelectedElements( - getNonDeletedElements(elements), - appState, - { - includeBoundTextElement: true, - includeElementsInFrames: true, - }, - ); + const selectedElements = app.scene.getSelectedElements({ + selectedElementIds: appState.selectedElementIds, + includeBoundTextElement: true, + includeElementsInFrames: true, + }); if (selectedElements.some((element) => element.type === "image")) { return { commitToHistory: false, diff --git a/src/actions/actionAlign.tsx b/src/actions/actionAlign.tsx index d917f803..5697a707 100644 --- a/src/actions/actionAlign.tsx +++ b/src/actions/actionAlign.tsx @@ -13,19 +13,18 @@ import { ExcalidrawElement } from "../element/types"; import { updateFrameMembershipOfSelectedElements } from "../frame"; import { t } from "../i18n"; import { KEYS } from "../keys"; -import { getSelectedElements, isSomeElementSelected } from "../scene"; -import { AppState } from "../types"; +import { isSomeElementSelected } from "../scene"; +import { AppClassProperties, AppState } from "../types"; import { arrayToMap, getShortcutKey } from "../utils"; import { register } from "./register"; const alignActionsPredicate = ( elements: readonly ExcalidrawElement[], appState: AppState, + _: unknown, + app: AppClassProperties, ) => { - const selectedElements = getSelectedElements( - getNonDeletedElements(elements), - appState, - ); + const selectedElements = app.scene.getSelectedElements(appState); return ( selectedElements.length > 1 && // TODO enable aligning frames when implemented properly @@ -36,12 +35,10 @@ const alignActionsPredicate = ( const alignSelectedElements = ( elements: readonly ExcalidrawElement[], appState: Readonly, + app: AppClassProperties, alignment: Alignment, ) => { - const selectedElements = getSelectedElements( - getNonDeletedElements(elements), - appState, - ); + const selectedElements = app.scene.getSelectedElements(appState); const updatedElements = alignElements(selectedElements, alignment); @@ -50,6 +47,7 @@ const alignSelectedElements = ( return updateFrameMembershipOfSelectedElements( elements.map((element) => updatedElementsMap.get(element.id) || element), appState, + app, ); }; @@ -57,10 +55,10 @@ export const actionAlignTop = register({ name: "alignTop", trackEvent: { category: "element" }, predicate: alignActionsPredicate, - perform: (elements, appState) => { + perform: (elements, appState, _, app) => { return { appState, - elements: alignSelectedElements(elements, appState, { + elements: alignSelectedElements(elements, appState, app, { position: "start", axis: "y", }), @@ -69,9 +67,9 @@ export const actionAlignTop = register({ }, keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_UP, - PanelComponent: ({ elements, appState, updateData }) => ( + PanelComponent: ({ elements, appState, updateData, app }) => (