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 3 years ago
parent
commit
269a035bec
No account linked to committer's email address

+ 1
- 0
.gitignore View File

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

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

15
   )
15
   )
16
 
16
 
17
   // When the editor mounts, save the state instance in a ref.
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
   // When the editor's document changes, post the stringified document to the vscode extension.
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
     vscode.postMessage({
24
     vscode.postMessage({
25
       type: 'editorUpdated',
25
       type: 'editorUpdated',
26
       text: JSON.stringify({
26
       text: JSON.stringify({
27
         ...currentFile,
27
         ...currentFile,
28
-        document: state.document,
28
+        document: app.document,
29
         assets: {},
29
         assets: {},
30
       } as TDFile),
30
       } as TDFile),
31
     } as MessageFromWebview)
31
     } as MessageFromWebview)
37
       if (data.type === 'openedFile') {
37
       if (data.type === 'openedFile') {
38
         try {
38
         try {
39
           const { document } = JSON.parse(data.text) as TDFile
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
         } catch (e) {
43
         } catch (e) {
43
           console.warn('Failed to parse file:', data.text)
44
           console.warn('Failed to parse file:', data.text)
44
         }
45
         }

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

2
 	"name": "tldraw-vscode",
2
 	"name": "tldraw-vscode",
3
 	"displayName": "tldraw",
3
 	"displayName": "tldraw",
4
 	"description": "The tldraw Extension for VS Code.",
4
 	"description": "The tldraw Extension for VS Code.",
5
-	"version": "1.1.0",
5
+	"version": "1.1.1",
6
 	"license": "MIT",
6
 	"license": "MIT",
7
 	"publisher": "tldraw-org",
7
 	"publisher": "tldraw-org",
8
 	"repository": {
8
 	"repository": {
52
 			}
52
 			}
53
 		],
53
 		],
54
 		"keybindings": [
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
 				"key": "cmd+numpad_add",
63
 				"key": "cmd+numpad_add",
57
 				"title": "Zoom In",
64
 				"title": "Zoom In",
119
 		"vsce": "^2.2.0"
126
 		"vsce": "^2.2.0"
120
 	},
127
 	},
121
 	"gitHead": "325008ff82bd27b63d625ad1b760f8871fb71af9"
128
 	"gitHead": "325008ff82bd27b63d625ad1b760f8871fb71af9"
122
-}
129
+}

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

15
   private static readonly viewType = 'tldraw.tldr'
15
   private static readonly viewType = 'tldraw.tldr'
16
 
16
 
17
   public static register = (context: vscode.ExtensionContext): vscode.Disposable => {
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
       const name = id > 1 ? `New Document ${id}.tldr` : `New Document.tldr`
28
       const name = id > 1 ? `New Document ${id}.tldr` : `New Document.tldr`
23
 
29
 
24
       const workspaceFolders = vscode.workspace.workspaceFolders
30
       const workspaceFolders = vscode.workspace.workspaceFolders
27
       vscode.commands.executeCommand(
33
       vscode.commands.executeCommand(
28
         'vscode.openWith',
34
         'vscode.openWith',
29
         vscode.Uri.joinPath(path, name).with({ scheme: 'untitled' }),
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
     // Register our editor provider, indicating to VS Code that we can
40
     // Register our editor provider, indicating to VS Code that we can
47
     // handle files with the .tldr extension.
41
     // handle files with the .tldr extension.
48
     return vscode.window.registerCustomEditorProvider(
42
     return vscode.window.registerCustomEditorProvider(
49
-      TldrawEditorProvider.viewType,
43
+      this.viewType,
50
       new TldrawEditorProvider(context),
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
         supportsMultipleEditorsPerDocument: true,
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