浏览代码

fix: group/ungroup shortcuts

Peng Xiao 2 年之前
父节点
当前提交
ea92147bea

+ 10 - 0
tldraw/apps/tldraw-logseq/src/components/ContextMenu/ContextMenu.tsx

@@ -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 && (
@@ -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" />

+ 6 - 4
tldraw/packages/core/src/lib/TLApi/TLApi.ts

@@ -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 - 0
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -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