Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

Plan: Add VS Code Extension Platform for Learningmap

Understanding of the repository:

  • Monorepo with pnpm workspaces
  • Core @learningmap/learningmap package exports LearningMapEditor component
  • Editor uses Zustand for state management with getRoadmapData() and loadRoadmapData() methods
  • File extension is .learningmap (JSON format)
  • Existing platforms: web (React SPA)

Implementation Plan

  • Explore repository structure and understand existing code
  • Create platforms/vscode directory structure
  • Set up VS Code extension with required configuration files
  • Create webview panel to host the React LearningMapEditor
  • Implement bidirectional communication between extension and webview
  • Add command for creating new learningmap files
  • Build configuration (esbuild for bundling)
  • Update workspace configuration to include vscode platform
  • Improve save logic with debouncing and race condition prevention
  • Add documentation and debugging configuration
  • Address code review feedback (type safety, security)
  • Run security scan (CodeQL - no issues found)
  • Update main documentation
  • Remove sharing functionality in VS Code extension
  • Add browser support for github.dev
  • Hide open and download buttons
  • Add command to show source
  • Update web-component and documentation with new props
  • Fix show source command for custom editors
  • Make keyboard shortcuts configurable via VS Code keybindings
  • Add configurable keybindings prop to React component
  • Make ALL editor keybindings configurable in VS Code

Features

Visual Editor

  • Custom editor for .learningmap files with visual editing interface
  • Auto-save with 500ms debouncing
  • Support for empty .learningmap files
  • Works in both desktop VS Code and browser environments (github.dev, vscode.dev)

Commands

  • New Learningmap: Create new learningmap files via command palette
  • Show Source: View/edit JSON source with configurable keyboard shortcut
  • 22 Editor Commands: All editor actions available as VS Code commands (add nodes, undo/redo, zoom, etc.)

Keyboard Shortcuts - Fully Configurable

All keyboard shortcuts are now fully configurable through VS Code:

VS Code Integration

  • 22 commands registered with VS Code's command system
  • All commands have default keybindings matching editor conventions
  • Commands scoped to learningmap editor using activeCustomEditorId context
  • Extension tracks active webview and dispatches commands
  • Webview receives commands and simulates keyboard events for React editor

Available Commands with Default Shortcuts:

  • Node operations: Add Task/Topic/Image/Text Node (Ctrl+1-4 / Cmd+1-4)
  • Edit operations: Undo (Ctrl+Z), Redo (Ctrl+Y), Cut/Copy/Paste, Select All, Delete
  • View operations: Zoom In/Out/Reset, Fit View, Zoom to Selection, Toggle Grid
  • Mode operations: Toggle Preview/Debug, Show Help, Reset Map

Customization:
Users can customize any shortcut through VS Code's keyboard shortcuts editor:

  1. Open Keyboard Shortcuts editor (Ctrl+K Ctrl+S / Cmd+K Cmd+S)
  2. Search for "Learningmap" to see all 22 commands
  3. Click pencil icon to change any shortcut or add additional bindings
  4. No conflicts with other VS Code shortcuts due to proper scoping

React Component Level:

  • keyBindings prop allows programmatic customization
  • Type-safe KeyBindings interface with properties for each shortcut
  • VS Code extension uses this to disable Ctrl+S (handled by VS Code)

Browser Compatibility

  • Uses Web Crypto API instead of Node.js crypto module
  • Includes "browser" field in package.json for proper environment detection
  • Full functionality in github.dev and vscode.dev

Core Package Updates

Added optional props to LearningMapEditor component for customizing the toolbar and keyboard shortcuts in different environments:

  • disableSharing - Hides the share button (useful for VS Code and embedded contexts)
  • disableFileOperations - Hides open and download buttons (useful when file operations are handled externally)
  • keyBindings - Customize all keyboard shortcuts programmatically (useful for avoiding conflicts in different environments)

These props are:

  • ✅ Exported in the React package API with full TypeScript types (KeyBinding, KeyBindings)
  • ✅ Exposed in the web-component wrapper as attributes (disable-sharing, disable-file-operations, key-bindings)
  • ✅ Fully documented in both React and web-component documentation with complete keyboard shortcuts table

Keyboard Shortcuts Customization Example

// React example - Programmatic customization
import { LearningMapEditor, KeyBindings } from '@learningmap/learningmap';

const customKeyBindings: Partial<KeyBindings> = {
  save: undefined, // Disable save shortcut
  addTaskNode: { key: 't', ctrl: true }, // Change from Ctrl+1 to Ctrl+T
};

<LearningMapEditor keyBindings={customKeyBindings} />
<!-- Web component example -->
<hyperbook-learningmap-editor
  key-bindings='{"save": null, "addTaskNode": {"key": "t", "ctrl": true}}'
></hyperbook-learningmap-editor>

Files Created

platforms/vscode/
├── src/
│   ├── extension.ts                    # Entry point, command registration (22 commands)
│   ├── LearningmapEditorProvider.ts    # Custom editor provider with command dispatch
│   └── webview.tsx                     # React webview wrapper with command handling
├── package.json                        # Extension manifest with 22 keybindings
├── tsconfig.json
├── icon.png
├── README.md                           # User documentation with keyboard shortcuts table
├── DEVELOPMENT.md                      # Developer documentation
├── .vscode/launch.json                 # Debug configuration
└── example.learningmap                 # Test file

Architecture

Command Flow:

  1. User presses keyboard shortcut in VS Code
  2. VS Code triggers the registered command
  3. Extension sends command message to active webview
  4. Webview simulates keyboard event
  5. React editor handles the event through existing keyboard shortcuts system

This architecture ensures all shortcuts are fully configurable through VS Code while maintaining compatibility with the React component's existing keyboard handling.

Original prompt

Add platform vscode. This should be a vscode extension which uses the LearningmapEditor for editing local learningmap files. The file extension ist "learningmap™. if i open a learningmap file, I want to open the editor. the changes in the editor should be written into the file. there should also ve a menu entry for creating a new learningmap. it should also ve possible to open a file with no contant, but the learningmap extension. also explor if their need to be changes in the other packages to make this word.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link

vercel bot commented Nov 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
learningmap Ready Ready Preview Comment Nov 2, 2025 6:41pm

- Create platforms/vscode with extension, custom editor provider, and webview
- Add build script for bundling extension and webview separately
- Support for opening .learningmap files with visual editor
- Add command for creating new learningmap files
- Auto-save changes back to file
- Support for empty .learningmap files

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
- Add debounced saving to prevent race conditions
- Prevent save loops by tracking loading state
- Add icon, keywords, and repository info to package.json
- Create DEVELOPMENT.md with architecture documentation
- Add VS Code launch configuration for debugging
- Document known limitations (share feature, URL hash loading)

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
- Remove unused CSS options from build script
- Add proper type definition for VS Code API instead of using 'any'
- Use crypto.randomBytes() for secure nonce generation instead of Math.random()
- Add example.learningmap file for testing

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
- Add VS Code platform to repository structure in development docs
- Add section on developing the VS Code extension
- Update main README with platforms section
- Link to platform-specific documentation

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add vscode extension for editing learningmap files Add VS Code extension platform for editing .learningmap files Nov 1, 2025
Copilot AI requested a review from mikebarkmin November 1, 2025 23:30
@mikebarkmin
Copy link
Member

@copilot remove the sharing functionality in the vscode extension. also make the extension work in the browser for example in github.dev

…nsion

- Add disableSharing prop to LearningMapEditor and EditorToolbar components
- Conditionally hide share button when disableSharing is true
- Enable disableSharing in VS Code webview
- Replace Node.js crypto module with Web Crypto API for browser compatibility
- Add "browser" field to package.json for github.dev support
- Use crypto.getRandomValues() which works in both Node.js and browser environments

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot remove the sharing functionality in the vscode extension. also make the extension work in the browser for example in github.dev

Done in commit ccd6d82:

  1. Sharing functionality removed: Added a disableSharing prop to the LearningMapEditor component that hides the share button in the toolbar. The VS Code extension now passes disableSharing={true}.

  2. Browser support added:

    • Replaced Node.js crypto module with Web Crypto API (crypto.getRandomValues()) which works in both Node.js and browser environments
    • Added "browser" field to package.json to enable the extension in github.dev and vscode.dev

The extension should now work seamlessly in both desktop VS Code and browser-based environments like github.dev.

Copilot AI changed the title Add VS Code extension platform for editing .learningmap files Add VS Code extension platform for editing .learningmap files (with browser support) Nov 2, 2025
@mikebarkmin
Copy link
Member

@copilot when opening a file the learningmapeditor should be directly visible. add a command to show the source. also hide the buttons for open and download.

- Add disableFileOperations prop to LearningMapEditor and EditorToolbar
- Conditionally hide open and download buttons when disableFileOperations is true
- Enable disableFileOperations in VS Code webview
- Add "Learningmap: Show Source" command to view JSON source
- Visual editor is now the default view (custom editors always open in custom view)
- Users can use the new command to switch to source view when needed

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot when opening a file the learningmapeditor should be directly visible. add a command to show the source. also hide the buttons for open and download.

Done in commit dc9404d:

  1. Visual editor opens directly: .learningmap files now automatically open in the visual editor by default (this is the standard behavior for VS Code custom editors).

  2. Show source command added: Added "Learningmap: Show Source" command that switches to the text editor view to see/edit the JSON source. Access via Command Palette (Ctrl+Shift+P or Cmd+Shift+P) → "Learningmap: Show Source".

  3. Open and download buttons hidden: Added disableFileOperations prop that hides these buttons in the VS Code extension since file operations are handled by VS Code itself (Ctrl+O to open, Ctrl+S to save).

- Check workspace.textDocuments for open .learningmap files when no active text editor
- Fall back to visible text editors if available
- Properly handle the case when custom editor is active (no activeTextEditor)
- Improved error message clarity

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot showing source does not work. I get an error no active learningmap.

Fixed in commit 1129708.

The issue was that custom editors (like our visual learningmap editor) don't have an activeTextEditor - they use webview panels instead. The command was only checking vscode.window.activeTextEditor which returns undefined when the custom editor is active.

Fix: The command now:

  1. Checks activeTextEditor first (in case source view is already open)
  2. Falls back to visibleTextEditors if available
  3. Searches workspace.textDocuments for any open .learningmap files
  4. Shows a clearer error message if no learningmap file is found

The "Show Source" command should now work correctly when the visual editor is active.

@mikebarkmin
Copy link
Member

@copilot make the keyboard shortcuts configurable.

- Add keybindings contribution to package.json for Show Source command
- Default shortcut: Ctrl+K Ctrl+S (Windows/Linux) or Cmd+K Cmd+S (Mac)
- Users can customize shortcuts via VS Code keyboard shortcuts editor
- Update README with keyboard shortcuts documentation
- Document how to customize shortcuts in VS Code

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot make the keyboard shortcuts configurable.

Done in commit cd2261b.

Added configurable keyboard shortcuts:

  • Added keybindings contribution to package.json
  • Default shortcut for "Show Source": Ctrl+K Ctrl+S (Windows/Linux) or Cmd+K Cmd+S (Mac)

Users can customize shortcuts:

  1. Open VS Code Keyboard Shortcuts editor (Ctrl+K Ctrl+S or Cmd+K Cmd+S)
  2. Search for "Learningmap"
  3. Click the pencil icon next to the command to change the shortcut

Note: The editor shortcuts (like Ctrl+1 for adding task nodes, Ctrl+Z for undo, etc.) are handled by the React component inside the webview and work as documented. The VS Code keybindings contribution is specifically for extension-level commands like "Show Source". All shortcuts are now user-customizable through VS Code's standard keyboard shortcuts configuration.

@mikebarkmin
Copy link
Member

@copilot modify the react component to accept the keybondings as a prop and use that for custom keybindings in vscode. also update the documentation.

- Add KeyBinding and KeyBindings types to define custom keyboard shortcuts
- Update KeyboardShortcuts component to accept and use custom keybindings
- Add keyBindings prop to LearningMapEditor component
- VS Code extension now disables Ctrl+S (save) since VS Code handles saving
- Export KeyBinding and KeyBindings types from package
- Update web-component to support key-bindings attribute
- Document keyboard shortcuts and customization in React docs
- Document key-bindings attribute in web-component docs

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot modify the react component to accept the keybondings as a prop and use that for custom keybindings in vscode. also update the documentation.

Done in commit 761eb36.

Added keyBindings prop to LearningMapEditor:

  • New KeyBinding and KeyBindings types define the structure for custom keyboard shortcuts
  • All 20+ default shortcuts can now be customized or disabled
  • VS Code extension uses this to disable Ctrl+S (VS Code handles save)

Usage example:

import { LearningMapEditor, KeyBindings } from '@learningmap/learningmap';

const customBindings: Partial<KeyBindings> = {
  save: undefined, // Disable
  addTaskNode: { key: 't', ctrl: true } // Change to Ctrl+T
};

<LearningMapEditor keyBindings={customBindings} />

Updated:

  • Web-component now supports key-bindings attribute (JSON string)
  • React docs include complete keyboard shortcuts table and customization examples
  • Web-component docs explain how to pass custom keybindings as JSON
  • All shortcuts are now fully configurable and type-safe

Copilot AI changed the title Add VS Code extension platform for editing .learningmap files (with browser support) Add VS Code extension platform for editing .learningmap files (with browser support and configurable keyboard shortcuts) Nov 2, 2025
@mikebarkmin
Copy link
Member

@copilot can you make all keybindings configurable in the vscode extension?

- Add VS Code commands for all 21 editor actions (add nodes, undo/redo, zoom, etc.)
- Register keybindings for all commands in package.json with proper when clauses
- Update LearningmapEditorProvider to track active webview and send commands
- Update webview to handle command messages and simulate keyboard events
- All shortcuts scoped to learningmap editor using 'activeCustomEditorId' context
- Users can customize any shortcut through VS Code keyboard shortcuts editor
- Update README with complete keyboard shortcuts table and customization instructions

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot can you make all keybindings configurable in the vscode extension?

Done in commit 24dde25.

All 21 editor keybindings are now configurable in VS Code:

Added VS Code commands and keybindings for:

  • Node operations: Add Task/Topic/Image/Text Node (Ctrl+1-4)
  • Edit operations: Undo/Redo, Cut/Copy/Paste, Select All, Delete
  • View operations: Zoom In/Out/Reset, Fit View, Zoom to Selection, Toggle Grid
  • Mode operations: Toggle Preview/Debug, Show Help, Reset Map

How it works:

  1. Extension registers 21 commands in package.json with default keybindings
  2. Commands are scoped to learningmap editor using activeCustomEditorId context
  3. Extension tracks active webview and dispatches commands to it
  4. Webview receives commands and simulates keyboard events for the React editor

Users can customize:

  • Open Keyboard Shortcuts editor (Ctrl+K Ctrl+S)
  • Search for "Learningmap"
  • Click pencil icon to change any shortcut

All shortcuts are now fully integrated with VS Code's keyboard shortcut system, allowing users to customize them per their preferences or resolve conflicts with other extensions.

Copilot AI changed the title Add VS Code extension platform for editing .learningmap files (with browser support and configurable keyboard shortcuts) Add VS Code extension platform for editing .learningmap files (with browser support and fully configurable keyboard shortcuts) Nov 2, 2025
@mikebarkmin mikebarkmin marked this pull request as ready for review November 2, 2025 18:59
@mikebarkmin mikebarkmin merged commit a6af8b8 into main Nov 2, 2025
2 checks passed
@mikebarkmin mikebarkmin deleted the copilot/add-vscode-extension-learningmap branch November 2, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants