The original was a NSTextView wrapper. Jump forward 20 years, a few failed rewrites, and I've built something new. From the simplest thing that could possibly work, to the opposite! This version is built from scratch. Maybe not smart, but has some benefits.
Here's what I did and what it allowed me.
WriteRoom is a Swift document based app. It supports macOS technologies back to AppleScript. It also supports Shortcuts and a terminal command with MCP. I think it's a Mac-assed app.
The editor component is custom built in Rust, using the GPU for display. At a high level the editor is:
1. Ropey[^1] crate for text storage
2. Ported/Modified CodeMirror Markdown tree
3. Sorted range lists, for selection, folds and annotations
4. CodeMirror-style height map tree for scrolling
5. WGPU crate for text atlas drawing
6. CoreText for text shaping/layout
7. Wrapped in NSView for native scrolling, integration
What fun things does this setup allow?
Flexible themes. Such as a DEC terminal as described in [^2]. Scanlines are applied at text atlas level to DEC ROM characters. Optional screen curvature is also applied. Can't do that with NSTextView.
Extreme performance. I test with the Moby Dick Workout [^3] * 1000. Over a gigabyte of Markdown structure loads in about a second and finishes parsing a few seconds later. Typing/scrolling/etc feel as fast as when typing in an empty document. Full control makes it possible to make things really fast.
Word/char counts are surprisingly expensive. Ropey and the Markdown tree are both cheap to snapshot because they share structure, so the parse and the word count both run on background threads and catch up while you type.
Mixing in IDE features such as sticky headings and minimap scrollers. That at runtime require an markdown tree for good performance and ability to do a lot of fast text drawing.
Numbered headings is another nice feature, but hard to implement without custom markdown tree. The feature is that your ### headings are rendered as numbers, so you might see 1.2.3 for a level 3 heading in first section. Feels quite nice and different in longer structured documents.
Overview mode is another feature, it mixes the minimap display with your regular document. So for example you can "zoom" and see your headings in normal text while everything else is minimap. All with a fast smooth animation. Inspired by MakePad editor[^4].
Thoughts and questions welcome.
[^1] Ropey – A UTF8 text rope for editing large text - https://news.ycombinator.com/item?id=42711966
[^2] Raster CRT Typography (According to DEC) - https://news.ycombinator.com/item?id=19528618
[^3] Moby Dick Workout - https://news.ycombinator.com/item?id=48791266
[^4] MakePad - https://makepad.dev