Skip to content

Commit

Permalink
Adds delete selection
Browse files Browse the repository at this point in the history
  • Loading branch information
steveruizok committed Oct 29, 2021
1 parent c54aabc commit 44dce33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
23 changes: 12 additions & 11 deletions example-advanced/src/shapes/box/BoxUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ export class BoxUtil extends TLShapeUtil<T, E> {
Indicator = BoxIndicator

getBounds = (shape: T) => {
const [x, y] = shape.point
const [width, height] = shape.size
const bounds = Utils.getFromCache(this.boundsCache, shape, () => {
const [width, height] = shape.size

const bounds: TLBounds = {
minX: x,
maxX: x + width,
minY: y,
maxY: y + height,
width,
height,
} as TLBounds
return {
minX: 0,
maxX: width,
minY: 0,
maxY: height,
width,
height,
} as TLBounds
})

return bounds
return Utils.translateBounds(bounds, shape.point)
}

getCenter = (shape: T) => {
Expand Down
8 changes: 7 additions & 1 deletion example-advanced/src/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const state = createState({
onEnter: 'clearJustShiftSelectedId',
on: {
CANCELLED: 'clearSelection',
DELETED: 'deleteSelection',
POINTED_CANVAS: [
{
unless: 'isPressingShiftKey',
Expand Down Expand Up @@ -368,7 +369,12 @@ export const state = createState({
},
/* ----------------- Shape Deleting ----------------- */
deleteSelection(data) {
data.pageState.selectedIds.forEach((id) => delete data.page.shapes[id])
const { page, pageState } = data
if (pageState.hoveredId && pageState.selectedIds.includes(pageState.hoveredId)) {
pageState.hoveredId = undefined
}
pageState.selectedIds.forEach((id) => delete page.shapes[id])
pageState.selectedIds = []
},
/* ------------------- Translating ------------------ */
translateSelection(data, payload: TLPointerInfo) {
Expand Down
23 changes: 11 additions & 12 deletions example/src/shapes/box/BoxUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ export class BoxUtil extends TLShapeUtil<T, E> {
Indicator = BoxIndicator

getBounds = (shape: T) => {
const bounds = Utils.getFromCache(this.boundsCache, shape, () => {
const [width, height] = shape.size
const [x, y] = shape.point
const [width, height] = shape.size

return {
minX: 0,
maxX: width,
minY: 0,
maxY: height,
width,
height,
} as TLBounds
})
const bounds: TLBounds = {
minX: x,
maxX: x + width,
minY: y,
maxY: y + height,
width,
height,
} as TLBounds

return Utils.translateBounds(bounds, shape.point)
return bounds
}
}

0 comments on commit 44dce33

Please sign in to comment.