Skip to content

A professional iOS code editor featuring smooth syntax highlighting, line numbers, and minimap. Built with safety and performance first.

License

Notifications You must be signed in to change notification settings

AndrewMason7/PandyEditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐼 Pandy Editor

Pandy Editor Icon

A professional-grade, high-performance code editor component for iOS
Engineered to Strict FiveKit Compliance

FiveKit Certified iOS 15+ Swift 5.9 Tests Passing


πŸ“– Overview

Pandy Editor is not just a UITextView wrapper. It is a fully engineered code editing environment built on the FiveKit architecture.

Why "Pandy"?

  • 🐼 Gentle - Won't crash, even with malformed input
  • 🐼 Calm - Smooth 120Hz scrolling, no UI stutter
  • 🐼 Cuddly - Friendly, easy to integrate

Core Principles

Principle Implementation
Lag Prevention View Diffing + Viewport Optimization
Crash Prevention Safety Quadruple (4-layer guards)
Thread Safety Main thread UI, background computation
Expressive Code FiveKit syntax (.negated, text[i])

✨ Key Features

⚑️ FiveKit Engineered

  • ProMotion Optimized: Uses "View Diffing" to minimize layer updates during typing and scrolling, ensuring buttery smooth performance on 120Hz devices.
  • Safety Quadruple: All UI operations are protected by four layers of safety guards (Feature Flag, Window Check, Thread Safety, Layout Validity).
  • FoundationPlus: Built using expressive, safe syntax (.negated, String.empty, text[i]) provided via FiveKit export.
  • Branch Dependency: FiveKit uses branch: "main"

πŸš€ Performance Optimizations

  • Viewport-Based Highlighting: Syntax colors are only applied to the visible range + 50% buffer. A 10,000-line file only highlights ~50 lines at a time.
  • Bracket Matching Cache: Cursor position is cached to avoid O(n) re-scans when the cursor hasn't moved.
  • Atomic Text Versioning: Rapid keystrokes invalidate stale background work, preventing race conditions.
  • Regex Caching: Patterns are compiled once per language, reused forever.
  • Large File Protection: Files >150K characters gracefully degrade to plain text.

πŸ›  Editor Capabilities

  • Syntax Highlighting: Real-time highlighting for 11 languages (Swift, Python, JS, TS, Go, Rust, SQL, HTML, CSS, JSON, Plain Text).
  • Line Numbers: Integrated, synchronized gutter with O(log n) binary search.
  • Minimap: Scaled, clickable code overview with background rendering.
  • Bracket Matching: Rainbow brackets with intelligent matching.
  • Current Line Highlight: Subtle background highlight for better orientation.
  • Keyboard Toolbar: Language-specific quick keys with cursor glide.
  • Rich Theming: 9 professionally tuned themes (5 Dark + 4 Light).

πŸ“¦ Installation

Add the following to your Package.swift dependencies:

dependencies: [
    .package(url: "https://github.com/AndrewMason7/PandyEditor.git", branch: "main"),
]

πŸš€ Usage

SwiftUI (Recommended)

Use the PandyEditor wrapper for a seamless SwiftUI experience:

import PandyEditor

struct ContentView: View {
    @State private var code = "func hello() {}"
    
    var body: some View {
        PandyEditor(text: $code, language: .swift, theme: .oneDarkPro)
            .showLineNumbers(true)
            .showMinimap(true)
            .edgesIgnoringSafeArea(.all)
    }
}

UIKit (Advanced)

The EditorView manages its own subcomponents (Line Numbers, Highlight Views). Just instantiate and configure:

import PandyEditor

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // 1. Create the editor
        let editor = EditorView()
        editor.frame = view.bounds
        editor.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        
        // 2. Configure Syntax & Theme
        editor.setLanguage(.swift)
        editor.setTheme(.oneDarkPro)
        
        // 3. Enable Features
        editor.showLineNumbers = true
        editor.showMinimap = true
        editor.showCurrentLineHighlight = true
        editor.showBracketMatching = true
        
        // 4. Set Content
        editor.text = """
        func greet() {
            print("Hello, Pandy Editor! 🐼")
        }
        """
        
        view.addSubview(editor)
    }
}

🎨 Available Themes

Dark Themes:

Theme Style
.oneDarkPro VS Code inspired (Default)
.modernDark Premium Blue/Slate
.githubDark GitHub style
.dracula Classic purple/pink
.catppuccinMocha Pastel dark

Light Themes:

Theme Style
.githubLight GitHub style
.xcodeLight Apple classic
.atomOneLight Atom-inspired
.solarizedLight Low contrast

πŸ’» Supported Languages

Language Extensions Quick Keys
Plain Text .txt, .md Generic punctuation
Swift .swift func, guard, let, ->
JavaScript .js, .jsx, .mjs const, =>, function
TypeScript .ts, .tsx interface, type, async
Python .py, .pyw def, class, self
Go .go func, :=, chan, defer
Rust .rs fn, mut, impl, match
SQL .sql SELECT, FROM, WHERE
HTML .html, .htm <, >, div, class
CSS .css, .scss px, rem, !important
JSON .json true, false, null

πŸ— Architecture

The project follows the FiveKit Modular Pattern:

PandyEditor/
β”œβ”€β”€ Sources/PandyEditor/
β”‚   β”œβ”€β”€ Editor/                     # Core Components
β”‚   β”‚   β”œβ”€β”€ PandyEditor.swift           # SwiftUI Wrapper ("Harmony File")
β”‚   β”‚   β”œβ”€β”€ EditorView.swift            # Main Class Definition
β”‚   β”‚   β”œβ”€β”€ EditorView+API.swift        # Public API & User Controls
β”‚   β”‚   β”œβ”€β”€ EditorView+Bracket.swift    # Bracket Matching
β”‚   β”‚   β”œβ”€β”€ EditorView+Keyboard.swift   # Keyboard & Toolbar Delegation
β”‚   β”‚   β”œβ”€β”€ EditorView+Layout.swift     # Layout & Rendering
β”‚   β”‚   β”œβ”€β”€ EditorView+Setup.swift      # Initialization
β”‚   β”‚   β”œβ”€β”€ LineNumberView.swift        # Gutter (O(log n) lookup)
β”‚   β”‚   β”œβ”€β”€ MinimapView.swift           # Code Overview
β”‚   β”‚   β”œβ”€β”€ KeyboardToolbarView.swift   # Quick Keys & Cursor Glide
β”‚   β”‚   β”œβ”€β”€ Syntax/                     # Highlighting Engine
β”‚   β”‚   β”‚   β”œβ”€β”€ EditorView+Syntax.swift     # Text Change Handling
β”‚   β”‚   β”‚   β”œβ”€β”€ SyntaxHighlighter.swift     # Two-Phase Optimizer
β”‚   β”‚   β”‚   └── SyntaxLanguages.swift       # 11 Language Definitions
β”‚   β”‚   └── UI/
β”‚   β”‚       └── ToolbarKeyCell.swift    # Keyboard Quick Key Cell
β”‚   β”œβ”€β”€ Theme/                      # Visual System
β”‚   β”‚   β”œβ”€β”€ CodeEditorTheme.swift       # Registry & Core
β”‚   β”‚   β”œβ”€β”€ CodeEditorTheme+Dark.swift  # 5 Dark Themes
β”‚   β”‚   └── CodeEditorTheme+Light.swift # 4 Light Themes
β”‚   β”œβ”€β”€ Utilities/                  # Safety & Extensions
β”‚   β”‚   β”œβ”€β”€ CrashGuard.swift            # Safety Quadruple Utilities
β”‚   β”‚   β”œβ”€β”€ Validator.swift             # Input Validation
β”‚   β”‚   └── Extensions/                 # Safe Type Extensions
β”‚   β”‚       β”œβ”€β”€ Array+Safe.swift            # Safe subscripting [safe:]
β”‚   β”‚       β”œβ”€β”€ String+Safe.swift           # Safe character access
β”‚   β”‚       β”œβ”€β”€ Data+Safe.swift
β”‚   β”‚       β”œβ”€β”€ URL+Safe.swift
β”‚   β”‚       └── FileManager+Safe.swift
β”‚   └── Resources/
β”‚       └── icon.jpg                    # Bundled Asset
└── Tests/PandyEditorTests/
    └── PandyEditorTests.swift          # Unit Tests

πŸ”„ Highlighting Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 PANDY EDITOR SYNTAX ENGINE                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 1: Global Context Scan (Full Document)               β”‚
β”‚  β”œβ”€β”€ Find all Strings  ───────────────────────► [ranges]    β”‚
β”‚  β”œβ”€β”€ Find all Comments ───────────────────────► [ranges]    β”‚
β”‚  └── Resolve Overlaps (First match wins)                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 2: Viewport Optimization                              β”‚
β”‚  β”œβ”€β”€ Calculate Visible Range + 50% Buffer                   β”‚
β”‚  └── Skip attribute application for off-screen ranges       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 3: Keyword Scan (Visible Code Gaps Only)             β”‚
β”‚  β”œβ”€β”€ Find Keywords  ──────────────────────────► [color]     β”‚
β”‚  β”œβ”€β”€ Find Numbers   ──────────────────────────► [color]     β”‚
β”‚  └── Find Functions ──────────────────────────► [color]     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ‘ Thank You

Special thanks to FiveSheep Co. for creating and maintaining:

Their work on developer tooling has made this project possible.

Check out the their extraordinary Mister Keyboard on the App Store β€” The infinitely customizable keyboard.


🐼 Credits

Pandy Editor

Built with ❀️

"Gentle. Calm. Cuddly."


πŸ“œ License

MIT License. Copyright (c) 2025 Andrew Mason.

About

A professional iOS code editor featuring smooth syntax highlighting, line numbers, and minimap. Built with safety and performance first.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages