brush selection when pressing meta tweak

This commit is contained in:
Steve Ruiz 2021-09-03 12:07:34 +01:00
parent adda205917
commit cb58a6c749
2 changed files with 29 additions and 33 deletions

View file

@ -104,7 +104,8 @@ function InnerTldraw() {
const isInSession = tlstate.session !== undefined
// Hide bounds when not using the select tool, or when the only selected shape has handles
const hideBounds = isInSession || !isSelecting || isSelectedHandlesShape
const hideBounds =
(tlstate.session && tlstate.session.id !== 'brush') || !isSelecting || isSelectedHandlesShape
// Hide bounds when not using the select tool, or when in session
const hideHandles = isInSession || !isSelecting

View file

@ -729,15 +729,17 @@ export class TLDrawState extends StateManager<Data> {
* @returns this
*/
copy = (ids = this.selectedIds): this => {
this.clipboard = ids.map((id) => {
const shape = this.getShape(id, this.currentPageId)
this.clipboard = ids
.flatMap((id) => TLDR.getDocumentBranch(this.state, id, this.currentPageId))
.map((id) => {
const shape = this.getShape(id, this.currentPageId)
return {
...shape,
id: Utils.uniqueId(),
childIndex: TLDR.getChildIndexAbove(this.state, id, this.currentPageId),
}
})
return {
...shape,
id: Utils.uniqueId(),
childIndex: TLDR.getChildIndexAbove(this.state, id, this.currentPageId),
}
})
return this
}
@ -794,10 +796,12 @@ export class TLDrawState extends StateManager<Data> {
if (!this.clipboard) return this
const idsMap = Object.fromEntries(this.clipboard.map((shape) => [shape.id, Utils.uniqueId()]))
const shapesToPaste = this.clipboard.map((shape) => ({
...shape,
id: Utils.uniqueId(),
parentId: this.currentPageId,
id: idsMap[shape.id],
parentId: idsMap[shape.parentId] || this.currentPageId,
}))
const commonBounds = Utils.getCommonBounds(shapesToPaste.map(TLDR.getBounds))
@ -2308,6 +2312,9 @@ export class TLDrawState extends StateManager<Data> {
switch (activeTool) {
case 'select': {
if (info.metaKey) {
if (!info.shiftKey) {
this.deselectAll()
}
// While holding just command key, start a brush session
this.startBrushSession(this.getPagePoint(info.point))
return
@ -2356,27 +2363,6 @@ export class TLDrawState extends StateManager<Data> {
break
}
case TLDrawStatus.PointingBounds: {
// If we've clicked on a shape that is inside of a group,
// then select the group rather than the shape.
// if (info.metaKey && info.shiftKey) {
// const targetId = this.pageState.hoveredId
// if (targetId) {
// this.pointedId = targetId
// const shape = this.getShape(targetId)
// if (this.selectedIds.includes(targetId)) {
// this.select(...this.selectedIds.filter((id) => id !== targetId))
// } else {
// if (this.selectedIds.includes(shape.parentId)) {
// this.select(targetId)
// } else {
// this.select(...this.selectedIds, targetId)
// }
// }
// return
// }
// }
const { parentId } = this.getShape(info.target)
this.pointedId = parentId === this.currentPageId ? info.target : parentId
@ -2459,7 +2445,16 @@ export class TLDrawState extends StateManager<Data> {
}
// Bounds (bounding box background)
onPointBounds: TLBoundsEventHandler = () => {
onPointBounds: TLBoundsEventHandler = (info) => {
if (info.metaKey) {
if (!info.shiftKey) {
this.deselectAll()
}
// While holding just command key, start a brush session
this.startBrushSession(this.getPagePoint(info.point))
return
}
this.setStatus(TLDrawStatus.PointingBounds)
}