Nerdy internals of an Apple text editor
papereditor.app
papereditor.app
That’s a new layout engine that currently is the default for text fields and on iOS and MacOS, but likely will be the only option some time in the future.
I want to migrate Paper to it this or next year.
I believe WordPad is the Windows equivalent, based on the RichEdit control.
Another fun fact is that RTF is basically the serialized form of NSAttributedString.
The same is true of Windows' RichEdit control. In fact, it looks like Windows' implementation came first: https://en.wikipedia.org/wiki/Rich_Text_Format
The benefit of using temporary attributes is that changing them is very fast compared to invoking the full transaction on NSTextStorage. For example, switching between Light/Dark modes is very fast in Paper.
Ideally, I would have expected it to behave like you have described.
How did you glean the information needed to write this? Other people’s code? Painful experience? developer.apple.com?
I've been working on Paper for 9 years. I've had a lot of time to study how everything works. :D
Incredible article btw
With attributes strings it’s trivial, you just need to move attributes accordingly and to normalize stuff at the end.
"paper writing app" is a good keyword to search by.
On Android, you basically have the Layout class (and its subclasses) that does everything related to both layout and rendering, and TextView which implements some of the editing/selection logic. The only difference between EditText and TextView is that EditText enables that editing functionality already present in TextView. The problem with this rather monolithic approach (and poor APIs) is that if you need more control over how your app renders text, you're out of luck. Want to get at the individual glyphs after they've been laid out for example? Nope, sorry.
Did you ever have to store custom metadata in NSAS to file? Before chatGPT, I had to write NSSecureCoding classes by hand, and that agony will remain in my soul next incarnation.
I am offloading all the storage to NSDocument, so I don't have to deal with stuff like this. :)
Just to repeat my years-long crusade of yelling at clouds, we need a cross platform, Rich Text HTML Document standard.
It's mostly about removing stuff from HTML - JavaScript, forms, and various CSS features - to make it focus on simple formatting. Then requiring the appropriate CSP security constraints to ensure privacy/security. Finally, standardizing on a way to include binary files (images, etc.) in the format using a JSON blob at the end of the text which can be referenced above.
Self contained, document focused, cross platform, secure and private, while still being standard HTML. Would replace ePub, .docx, Markdown, and provide a standard file format for Google Docs to export to.
All those features make TextView relatively slow and memory hungry. Because of that, I don’t think _text_ editors that handle multi-megabyte files will use a single NSAttributedString to store the entire document’s text.
For multi-megabyte files I always use Sublime.
The MarkEdit team uses WebView and have strong opinions about why.
The average user does not care.
The document-based app template gets you a lot for “free” too, including tabs and conversion of windows into tabs and vice versa.
This feels like a technical-first article that also happens to generate goodwill for the product, as opposed to a marketing-first technical article that serves up the bare minimum of insights.
Yep, it's a win-win. A good resource plus a bit of marketing for the product.
I would not say that developers are the target niche. The best customers are professional writers who use a ton of writing apps for different occasions.
Comments are now hidden in the Preview Mode.
I've also added the comment block feature (%%) like in Ulysses:
https://help.ulysses.app/en_US/guides/comments-notes-annotat...
Shortcuts:
- Comment: Command+T
- Comment Block: Shift+Command+T
Adjusting the preferred comment syntax:
- Mac: Go to the Format menu, hold the Option key, then under More Formatting below Comment you can pick either ++ or /**/
- iOS: Go to the Settings app, then under Paper > Markdown pick either ++ or /**/
I'll be sure to prioritize this work then. :D
Great post btw!
The state is saved to local storage. Just delete the key from DevTools and they will come back. :D
Never certain how it keeps for scrolling; the issue lies in drag, doomscrolls, scrollbar versus tap-for-scrolling… now, on topic of moving on: “a good OS citizen, you should provide many formats”, not keen on everything/too-many Media Formats keeping it sweet, simple; some of these Apps can become almost utility goto. Some of my favourites, include emoji meets paste formatting issues in export. How do they render correctly the almost, "interstitial flickering" change.
My expectations paused at Themes/Theming (not really happening? different looks) no simple mention of light Vs. dark; willow filter adjustment tones? Okay! Still, amazement. I believe, we choose our (kind of) Paper whenever possible.
…Thanks!
All the kindest of regards, from reading nerdy happenings! Kai V (@kaichanvong)
It's a shame because otherwise the presentation is really good.
The play/pause buttons are meant to not disturb the reading. They are only for the rare occasions when you want to pause the video to examine it closer.
Comments can be hovered over to make them fully visible.
The text, yes, should have been more prominent…