Browse Source

[chore] repo-map.tldr, vscode extension improvements (#332)

* v1.1.1

* add repo-map.tldr, minor changes to extension commands
main
Steve Ruiz 2 years ago
parent
commit
269a035bec
No account linked to committer's email address

+ 1
- 0
.gitignore View File

@@ -11,6 +11,7 @@ coverage
11 11
 
12 12
 .vercel
13 13
 .next
14
+apps/www/public/workbox-*
14 15
 apps/www/public/worker-*
15 16
 apps/www/public/sw.js
16 17
 apps/www/public/sw.js.map

+ 7
- 6
apps/vscode/editor/src/app.tsx View File

@@ -15,17 +15,17 @@ export default function App(): JSX.Element {
15 15
   )
16 16
 
17 17
   // When the editor mounts, save the state instance in a ref.
18
-  const handleMount = React.useCallback((state: TldrawApp) => {
19
-    rTldrawApp.current = state
18
+  const handleMount = React.useCallback((app: TldrawApp) => {
19
+    rTldrawApp.current = app
20 20
   }, [])
21 21
 
22 22
   // When the editor's document changes, post the stringified document to the vscode extension.
23
-  const handlePersist = React.useCallback((state: TldrawApp) => {
23
+  const handlePersist = React.useCallback((app: TldrawApp) => {
24 24
     vscode.postMessage({
25 25
       type: 'editorUpdated',
26 26
       text: JSON.stringify({
27 27
         ...currentFile,
28
-        document: state.document,
28
+        document: app.document,
29 29
         assets: {},
30 30
       } as TDFile),
31 31
     } as MessageFromWebview)
@@ -37,8 +37,9 @@ export default function App(): JSX.Element {
37 37
       if (data.type === 'openedFile') {
38 38
         try {
39 39
           const { document } = JSON.parse(data.text) as TDFile
40
-          const state = rTldrawApp.current!
41
-          state.updateDocument(document)
40
+          const app = rTldrawApp.current!
41
+          app.updateDocument(document)
42
+          app.zoomToFit()
42 43
         } catch (e) {
43 44
           console.warn('Failed to parse file:', data.text)
44 45
         }

+ 9
- 2
apps/vscode/extension/package.json View File

@@ -2,7 +2,7 @@
2 2
 	"name": "tldraw-vscode",
3 3
 	"displayName": "tldraw",
4 4
 	"description": "The tldraw Extension for VS Code.",
5
-	"version": "1.1.0",
5
+	"version": "1.1.1",
6 6
 	"license": "MIT",
7 7
 	"publisher": "tldraw-org",
8 8
 	"repository": {
@@ -52,6 +52,13 @@
52 52
 			}
53 53
 		],
54 54
 		"keybindings": [
55
+			{
56
+				"key": "cmd+shift+d",
57
+				"title": "Zoom In",
58
+				"command": "tldraw.tldr.toggleDarkMode",
59
+				"category": "tldraw",
60
+				"enablement": "resourceExtname == .tldr"
61
+			},
55 62
 			{
56 63
 				"key": "cmd+numpad_add",
57 64
 				"title": "Zoom In",
@@ -119,4 +126,4 @@
119 126
 		"vsce": "^2.2.0"
120 127
 	},
121 128
 	"gitHead": "325008ff82bd27b63d625ad1b760f8871fb71af9"
122
-}
129
+}

+ 13
- 24
apps/vscode/extension/src/TldrawEditorProvider.ts View File

@@ -15,10 +15,16 @@ export class TldrawEditorProvider implements vscode.CustomTextEditorProvider {
15 15
   private static readonly viewType = 'tldraw.tldr'
16 16
 
17 17
   public static register = (context: vscode.ExtensionContext): vscode.Disposable => {
18
-    // Register the 'Create new Tldraw file' command, which creates
19
-    // a temporary .tldr file and opens it in the editor.
20
-    vscode.commands.registerCommand('tldraw.tldr.new', () => {
21
-      const id = TldrawEditorProvider.newTDFileId++
18
+    // Several commands exist only to prevent the default keyboard shortcuts
19
+    const noopCmds = ['zoomIn', 'zoomOut', 'resetZoom', 'toggleDarkMode']
20
+    noopCmds.forEach((name) =>
21
+      vscode.commands.registerCommand(`${this.viewType}.${name}`, () => null)
22
+    )
23
+
24
+    // Register the 'Create New File' command, which creates a temporary
25
+    // .tldr file and opens it in the editor.
26
+    vscode.commands.registerCommand(`${this.viewType}.new`, () => {
27
+      const id = this.newTDFileId++
22 28
       const name = id > 1 ? `New Document ${id}.tldr` : `New Document.tldr`
23 29
 
24 30
       const workspaceFolders = vscode.workspace.workspaceFolders
@@ -27,34 +33,17 @@ export class TldrawEditorProvider implements vscode.CustomTextEditorProvider {
27 33
       vscode.commands.executeCommand(
28 34
         'vscode.openWith',
29 35
         vscode.Uri.joinPath(path, name).with({ scheme: 'untitled' }),
30
-        TldrawEditorProvider.viewType
36
+        this.viewType
31 37
       )
32 38
     })
33 39
 
34
-    vscode.commands.registerCommand('tldraw.tldr.zoomIn', () => {
35
-      // Noop
36
-    })
37
-
38
-    vscode.commands.registerCommand('tldraw.tldr.zoomOut', () => {
39
-      // Noop
40
-    })
41
-
42
-    vscode.commands.registerCommand('tldraw.tldr.resetZoom', () => {
43
-      // Noop
44
-    })
45
-
46 40
     // Register our editor provider, indicating to VS Code that we can
47 41
     // handle files with the .tldr extension.
48 42
     return vscode.window.registerCustomEditorProvider(
49
-      TldrawEditorProvider.viewType,
43
+      this.viewType,
50 44
       new TldrawEditorProvider(context),
51 45
       {
52
-        webviewOptions: {
53
-          // See https://code.visualstudio.com/api/extension-guides/webview#retaincontextwhenhidden
54
-          retainContextWhenHidden: true,
55
-        },
56
-
57
-        // See https://code.visualstudio.com/api/extension-guides/custom-editors#custom-editor-lifecycle
46
+        webviewOptions: { retainContextWhenHidden: true },
58 47
         supportsMultipleEditorsPerDocument: true,
59 48
       }
60 49
     )

+ 0
- 2
apps/www/public/workbox-7288c796.js
File diff suppressed because it is too large
View File


+ 0
- 1
apps/www/public/workbox-7288c796.js.map
File diff suppressed because it is too large
View File


+ 1501
- 0
repo-map.tldr
File diff suppressed because it is too large
View File


Loading…
Cancel
Save