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 const isInSession = tlstate.session !== undefined
// Hide bounds when not using the select tool, or when the only selected shape has handles // 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 // Hide bounds when not using the select tool, or when in session
const hideHandles = isInSession || !isSelecting const hideHandles = isInSession || !isSelecting

View file

@ -729,7 +729,9 @@ export class TLDrawState extends StateManager<Data> {
* @returns this * @returns this
*/ */
copy = (ids = this.selectedIds): this => { copy = (ids = this.selectedIds): this => {
this.clipboard = ids.map((id) => { this.clipboard = ids
.flatMap((id) => TLDR.getDocumentBranch(this.state, id, this.currentPageId))
.map((id) => {
const shape = this.getShape(id, this.currentPageId) const shape = this.getShape(id, this.currentPageId)
return { return {
@ -794,10 +796,12 @@ export class TLDrawState extends StateManager<Data> {
if (!this.clipboard) return this if (!this.clipboard) return this
const idsMap = Object.fromEntries(this.clipboard.map((shape) => [shape.id, Utils.uniqueId()]))
const shapesToPaste = this.clipboard.map((shape) => ({ const shapesToPaste = this.clipboard.map((shape) => ({
...shape, ...shape,
id: Utils.uniqueId(), id: idsMap[shape.id],
parentId: this.currentPageId, parentId: idsMap[shape.parentId] || this.currentPageId,
})) }))
const commonBounds = Utils.getCommonBounds(shapesToPaste.map(TLDR.getBounds)) const commonBounds = Utils.getCommonBounds(shapesToPaste.map(TLDR.getBounds))
@ -2308,6 +2312,9 @@ export class TLDrawState extends StateManager<Data> {
switch (activeTool) { switch (activeTool) {
case 'select': { case 'select': {
if (info.metaKey) { if (info.metaKey) {
if (!info.shiftKey) {
this.deselectAll()
}
// While holding just command key, start a brush session // While holding just command key, start a brush session
this.startBrushSession(this.getPagePoint(info.point)) this.startBrushSession(this.getPagePoint(info.point))
return return
@ -2356,27 +2363,6 @@ export class TLDrawState extends StateManager<Data> {
break break
} }
case TLDrawStatus.PointingBounds: { 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) const { parentId } = this.getShape(info.target)
this.pointedId = parentId === this.currentPageId ? info.target : parentId this.pointedId = parentId === this.currentPageId ? info.target : parentId
@ -2459,7 +2445,16 @@ export class TLDrawState extends StateManager<Data> {
} }
// Bounds (bounding box background) // 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) this.setStatus(TLDrawStatus.PointingBounds)
} }