Skip to content

A toy C++ text editor built from scratch with OpenGL rendering, targeting 60+ fps with GB-sized files.

Notifications You must be signed in to change notification settings

johnrobinsn/zed

Repository files navigation

Zed - High-Performance Text Editor

A C++ text editor built from scratch with OpenGL rendering, targeting 60+ fps with GB-sized files.

✅ What's Been Implemented

Core Architecture

  • Rope Data Structure - AVL-balanced tree (256-512 byte nodes) with O(log n) operations
  • X11/OpenGL Platform - Direct X11 window management with OpenGL 3.3 context
  • FreeType Font Rendering - Dynamic glyph atlas with subpixel antialiasing
  • Instanced Rendering - Single draw call for up to 100k glyphs per frame
  • Text Editing - Insert/delete operations using the rope structure
  • File I/O - Load and save text files

Technical Features

  • Header-only architecture for fast compilation
  • Unity build support (compiles in ~1 second)
  • Comprehensive rope unit tests (all passing)
  • Subpixel AA with gamma correction
  • HiDPI display support
  • LRU glyph atlas caching

🛠️ Build Requirements

# Install dependencies (Ubuntu/Debian)
sudo apt-get install -y libfreetype-dev libglew-dev libx11-dev

# Build
make unity

# Run
./zed [filename]

📁 Project Structure

zed/
├── Makefile              # Unity build system
├── src/
│   ├── main.cpp          # Entry point
│   ├── platform.h        # X11 window + OpenGL context (180 lines)
│   ├── rope.h            # AVL-balanced rope (407 lines)
│   ├── font.h            # FreeType + glyph atlas (229 lines)
│   ├── renderer.h        # Instanced text rendering (352 lines)
│   ├── shaders.h         # GLSL shaders (109 lines)
│   ├── editor.h          # Editor state + logic (126 lines)
│   └── config.h          # Configuration system (92 lines)
├── tests/
│   └── rope_test.cpp     # Rope unit tests (all passing!)
└── assets/
    ├── default_config.json
    └── default_theme.json

🎯 Current Status

Fully Functional:

  • Window creation and event handling
  • Text rendering with beautiful subpixel AA
  • Rope-based text buffer
  • Character insertion
  • File loading
  • Keyboard input

Working On:

  • Cursor rendering and navigation
  • Backspace/Delete handling
  • Text selection
  • Undo/redo system
  • File saving

🚀 Performance

  • Compilation: ~1 second unity build
  • Binary Size: 311KB
  • Target: 60+ fps with GB files
  • Rope Operations: O(log n) insert/delete/lookup

📊 Test Coverage

# Run rope tests
make test

All rope tests passing:

  • Creation and initialization
  • Insert operations
  • Delete operations
  • Character access
  • Large file handling (1000+ lines)

🔧 Technical Details

Rope Data Structure

  • AVL-balanced binary tree
  • Small nodes (256-512 bytes) for cache efficiency
  • Automatic rebalancing on insert/delete
  • Supports arbitrary file sizes

Rendering Pipeline

  1. Text → Rope structure
  2. Rope → Character sequence
  3. Characters → Glyph lookups (FreeType)
  4. Glyphs → Atlas packing (LRU eviction)
  5. Atlas coords → Instance data
  6. Single glDrawArraysInstanced() call

Shaders

  • Vertex: Orthographic projection + instance transform
  • Fragment: RGB subpixel AA + gamma correction
  • Configurable theme colors

📝 Configuration

Edit assets/default_config.json:

{
  "font": {
    "path": "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",
    "size": 14
  },
  "theme": {
    "background": "#1e1e1e",
    "foreground": "#d4d4d4",
    "cursor": "#00ff00",
    "selection": "#264f78"
  }
}

🎨 Features Roadmap

MVP (Phase 1) - In Progress

  • Rope data structure
  • Text rendering
  • File loading
  • Character insertion
  • Cursor rendering
  • Arrow key navigation
  • Backspace/Delete
  • File saving
  • Undo/redo

Phase 2

  • Multi-cursor editing
  • Search (find)
  • Command palette
  • Theme system

Phase 3

  • Replace (search & replace)
  • Syntax highlighting (background thread)
  • Line numbers
  • Minimap

📖 Architecture Decisions

  1. Rope over Gap Buffer - O(log n) ops, essential for multi-cursor and huge files
  2. Header-only - Fast compilation, easy to understand
  3. OpenGL 3.3 - Balance of performance and compatibility
  4. No text shaping - Simpler pipeline, Latin text only (for now)
  5. Subpixel AA - Highest quality rendering
  6. X11 direct - Full control, no framework overhead

🐛 Known Limitations

  • ASCII only (no UTF-8 yet)
  • No syntax highlighting yet
  • No line numbers
  • Limited keybindings
  • Linux only (X11)

📚 Specification

See SPEC.md for complete technical specification including:

  • Detailed architecture
  • Performance targets
  • Threading model
  • Memory management
  • Risk mitigation

🏗️ Development

# Unity build (fast)
make unity

# Regular build
make

# Clean
make clean

# Run tests
make test

# Run editor
./zed SPEC.md

📄 License

Built from scratch as an educational project demonstrating:

  • High-performance text rendering
  • Advanced data structures (AVL rope)
  • OpenGL instanced rendering
  • Modern C++ architecture

Status: MVP in active development - core systems fully functional!

About

A toy C++ text editor built from scratch with OpenGL rendering, targeting 60+ fps with GB-sized files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •