Fixes selection for shapes in a group

This commit is contained in:
Steve Ruiz 2021-06-04 18:56:46 +01:00
parent 4507f806f6
commit fcb11f19e3
6 changed files with 51 additions and 43 deletions

View file

@ -1,13 +1,18 @@
import Command from './command'
import history from '../history'
import { Data, ShapeStyles } from 'types'
import { getPage, getSelectedShapes } from 'utils/utils'
import { getDocumentBranch, getPage, getSelectedShapes } from 'utils/utils'
import { getShapeUtils } from 'lib/shape-utils'
import { current } from 'immer'
export default function styleCommand(data: Data, styles: Partial<ShapeStyles>) {
const { currentPageId } = data
const initialShapes = getSelectedShapes(current(data))
const cData = current(data)
const page = getPage(cData)
const { currentPageId } = cData
const shapesToStyle = Array.from(data.selectedIds.values())
.flatMap((id) => getDocumentBranch(data, id))
.map((id) => page.shapes[id])
history.execute(
data,
@ -18,7 +23,7 @@ export default function styleCommand(data: Data, styles: Partial<ShapeStyles>) {
do(data) {
const { shapes } = getPage(data, currentPageId)
for (const { id } of initialShapes) {
for (const { id } of shapesToStyle) {
const shape = shapes[id]
getShapeUtils(shape).applyStyles(shape, styles)
}
@ -26,7 +31,7 @@ export default function styleCommand(data: Data, styles: Partial<ShapeStyles>) {
undo(data) {
const { shapes } = getPage(data, currentPageId)
for (const { id, style } of initialShapes) {
for (const { id, style } of shapesToStyle) {
const shape = shapes[id]
getShapeUtils(shape).applyStyles(shape, style)
}