CodeCanvas is a lightweight, canvas-based code editor built using JavaScript and WebGL. It aims to provide a smooth and responsive coding experience directly within the browser. This editor is rendered on a WebGL texture and offers a basic code editor with syntax highlighting and other essential editor features.
This is project is an experiment to develop a simple code editor that works in a webgl texture. CodeCanvas can be used in browser with a canvas element or in a 3d game environment for say a 3d computer terminal that has a functional text editor. This project is still in active development and a roadmap is available in the docs
folder.
- Canvas Rendering: Utilizes HTML5 Canvas and WebGL for high-performance rendering.
- WebGL Rendering: Utilizes WebGL for rendering a text editor on a texture.
- Syntax Highlighting: Supports syntax highlighting for Python code out of the box.
- Line Numbers: Displays line numbers for better code navigation.
- Caret and Selection Management: Handles text input, cursor movement, and text selection.
- Clipboard Operations: Supports copy, cut, and paste operations using the clipboard API.
- Undo/Redo Functionality: Implements an undo manager to track changes and revert actions.
- Customizable Themes: Offers theming support to switch between different color schemes.
- Syntax Highlighting for Python: Supports only Python syntax highlighting for now.
- Web Browser: A modern web browser that supports HTML5 Canvas and WebGL (e.g., Chrome, Firefox, Edge).
- Node.js and npm: For setting up a development environment and managing dependencies.
-
Clone the Repository
git clone https://github.com/yourusername/codecanvas.git
-
Navigate to the Project Directory
cd codecanvas
-
Install Dependencies
npm install
-
Start the Development Server
npm run dev
This will start a local development server and open the editor in your default browser.
- Typing and Editing: Click on the editor canvas to focus and start typing your code.
- Cursor Movement: Use arrow keys to navigate through the code.
- Selection: Click and drag to select text or use
Shift
with arrow keys. - Clipboard Operations:
- Copy:
Ctrl+C
(orCmd+C
on Mac) - Cut:
Ctrl+X
(orCmd+X
on Mac) - Paste:
Ctrl+V
(orCmd+V
on Mac)
- Copy:
- Undo/Redo:
- Undo:
Ctrl+Z
(orCmd+Z
on Mac) - Redo:
Ctrl+Y
orCtrl+Shift+Z
(orCmd+Shift+Z
on Mac)
- Undo:
- Scrolling: Use the mouse wheel or trackpad to scroll through the code.
CodeCanvas comes with a few built-in themes, including Monokai, Light, and Dark. You can switch themes by calling the setTheme
method:
codeCanvas.setTheme('monokai'); // Options: 'monokai', 'light', 'dark'
To add a new theme, modify the themes.js
file and define your color scheme.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome!