o
odin.langpkg.dev
packages / app / odin-editor

odin-editor

267a8f3app

A complete single-file text editor written in Odin with raylib

No license · updated 3 months ago

Odin Editor

A complete, single-file text editor written in Odin with raylib. Under 1,000 lines, zero external dependencies beyond the Odin toolchain.

screenshot placeholder

Features

Editing

  • Text input (ASCII + UTF-8: Hiragana, Katakana, Latin-1, CJK symbols)
  • Enter, Tab (4 spaces), Backspace, Delete
  • Unlimited undo / redo (delta-based operation stack)

Cursor movement

  • ← → ↑ ↓ (up/down preserves preferred column)
  • Home / End — line start / end
  • Ctrl+Home / Ctrl+End — document start / end
  • PageUp / PageDown

Selection

  • Shift + any movement key
  • Mouse click + drag
  • Ctrl+A — select all

Clipboard

  • Ctrl+C copy, Ctrl+X cut, Ctrl+V paste (system clipboard)

File I/O

  • Open file from command-line argument
  • Ctrl+O — open (minibuffer prompt)
  • Ctrl+S — save
  • Ctrl+Shift+S — save as

UI

  • Line numbers gutter
  • Status bar: filename, dirty marker *, line/column, total lines, rune count
  • Minibuffer prompt for Open / Save As (Esc to cancel)
  • Transient message line (fades to help text after 3s)
  • Mouse wheel scrolling
  • Resizable window
  • Auto-detects a system monospace font (Menlo → SFNSMono → DejaVuSansMono → Consolas)

Install & Run

1. Install Odin

# macOS
brew install odin

# Or download from https://odin-lang.org/docs/install/

2. Build & run

git clone https://github.com/<your-user>/odin-editor.git
cd odin-editor

# Run directly
odin run .

# Open a file
odin run . -- path/to/file.txt

# Optimized release build
odin build . -o:speed -out:editor
./editor path/to/file.txt

Keybindings

Key Action
Ctrl+S Save
Ctrl+Shift+S Save As
Ctrl+O Open file
Ctrl+Z Undo
Ctrl+Y / Ctrl+Shift+Z Redo
Ctrl+A Select all
Ctrl+C / X / V Copy / Cut / Paste
Ctrl+D Delete forward character
Ctrl+Home / End Jump to document start / end
Tab Insert 4 spaces
Shift+<movement> Extend selection
Esc (in prompt) Cancel Open / Save As

Architecture

Single file: main.odin (~800 LOC).

  • Buffer: [dynamic]rune — simple, correct for UTF-8. O(n) inserts but fine for typical editing sessions.
  • Undo/redo: pair of operation stacks. Each Op stores the inserted/deleted runes plus cursor/anchor snapshots, so redo is free.
  • Selection: tracked as an anchor rune index (-1 = no selection) plus the cursor. sel_range() returns the normalized [lo, hi).
  • Rendering: only the visible line range is drawn each frame. Line positions are recomputed from scratch each frame — acceptable for small files, would be replaced by a line-index cache for larger ones.

Known Limitations

  • No horizontal scrolling (long lines overflow the right edge)
  • CJK ideographs (0x4E00..0x9FFF) aren't in the default codepoint atlas — extend build_codepoints() to include them, at the cost of a larger font texture
  • Full-width characters are rendered at half-width cursor columns, so Japanese-heavy lines will have a cursor-position offset
  • No syntax highlighting

Extension Ideas

  • Gap buffer or piece table (current [dynamic]rune is slow on multi-MB files)
  • Find / replace (Ctrl+F)
  • Multiple buffers / tabs
  • Syntax highlighting
  • Configurable keybindings
  • Soft line wrap

License

MIT