CodeMirror
A good editor component that I decided not to use.
CodeMirror is what you embed in a web page when you want text editing that already works. It’s careful, well maintained, and it solves problems that take years to even find.
Napkin doesn’t use it. The web app has no runtime dependencies at all—no framework, no editor component—and the editing surface is a hand-rolled contenteditable where a plain string is the source of truth and every keystroke is intercepted and applied by hand. Undo, copy, cut, and international input are all mine.
That decision is the source of most of the hard parts: where a cursor is allowed to sit, whether a value chip can be selected, whether iOS will hold a caret beside a non-editable element. It’s also why the JavaScript is about 11 KB, which was the whole point. I’d make the same call again.