Skip to content

Commit

Permalink
fix: group/ungroup shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored and tiensonqin committed Dec 16, 2022
1 parent dda5abd commit ea92147
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Expand Up @@ -133,6 +133,11 @@ export const ContextMenu = observer(function ContextMenu({
onClick={() => runAndTransition(app.api.unGroup)}
>
Ungroup
<div className="tl-menu-right-slot">
<span className="keyboard-shortcut">
<code>{MOD_KEY}</code> <code>SHIFT</code> <code>G</code>
</span>
</div>
</ReactContextMenu.Item>
)}
{app.selectedShapesArray.length > 1 && (
Expand All @@ -141,6 +146,11 @@ export const ContextMenu = observer(function ContextMenu({
onClick={() => runAndTransition(app.api.doGroup)}
>
Group
<div className="tl-menu-right-slot">
<span className="keyboard-shortcut">
<code>{MOD_KEY}</code> <code>G</code>
</span>
</div>
</ReactContextMenu.Item>
)}
<ReactContextMenu.Separator className="menu-separator" />
Expand Down
10 changes: 6 additions & 4 deletions tldraw/packages/core/src/lib/TLApi/TLApi.ts
Expand Up @@ -393,10 +393,12 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa

const shapesInGroups = this.app.shapesInGroups(selectedGroups)

// not using this.app.removeShapes because it also remove shapes in the group
this.app.currentPage.removeShapes(...selectedGroups)
this.app.persist()
if (selectedGroups.length > 0) {
// not using this.app.removeShapes because it also remove shapes in the group
this.app.currentPage.removeShapes(...selectedGroups)
this.app.persist()

this.app.setSelectedShapes(shapesInGroups)
this.app.setSelectedShapes(shapesInGroups)
}
}
}
12 changes: 12 additions & 0 deletions tldraw/packages/core/src/lib/TLApp/TLApp.ts
Expand Up @@ -181,6 +181,18 @@ export class TLApp<
this.selectedTool.transition('idle')
},
},
{
keys: 'mod+g',
fn: () => {
this.api.doGroup()
},
},
{
keys: 'mod+shift+g',
fn: () => {
this.api.unGroup()
},
},
]
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down

0 comments on commit ea92147

Please sign in to comment.