Live data from Hacker News

Nerdy internals of an Apple text editor

papereditor.app

51–60 of 93 posts

Re: Nerdy internals of an Apple text editor

#51

I clicked "hide these widgets" from the three dot dropdown menu on your animations and now I can't figure out how to bring them back. heh. Great post btw!

Thanks!

The state is saved to local storage. Just delete the key from DevTools and they will come back. :D

Re: Nerdy internals of an Apple text editor

#53

I'm a little confused at the part about decorative attributes being done outside of the editing transaction, saying "And they are not even aware of the transaction since they live in the NSLayoutManager itself, not in NSTextStorage". Decorative attributes like color do normally live in the NSTextStorage! Is the author implying that the colors applied to markdown characters are being done with NSLayoutManager's tempor…

Yes. NSTextStorage can also contain the same attributes as the temporary attributes (rendering attributes in TextKit 2). 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.

I would have expected a transaction to track whether any changes affect layout and avoid invalidating layout if only changing rendering attributes. I assume you've actually measured this though, and so I have to infer that this optimization does not in fact happen.

Re: Nerdy internals of an Apple text editor

#54
post #37

The UI of this doc is absolutely beautiful

There are several elements that are practically invisible though: play/pause buttons on the sides, comments in parentheses, explanatory text on graphics. It's a shame because otherwise the presentation is really good.

Thanks!

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…

Re: Nerdy internals of an Apple text editor

#56

Earlier quoted context omitted.

Yes. NSTextStorage can also contain the same attributes as the temporary attributes (rendering attributes in TextKit 2). 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.

I would have expected a transaction to track whether any changes affect layout and avoid invalidating layout if only changing rendering attributes. I assume you've actually measured this though, and so I have to infer that this optimization does not in fact happen.

Things might have changed already, but yes, when I measured it there was a noticeable difference.

Ideally, I would have expected it to behave like you have described.

Re: Nerdy internals of an Apple text editor

#57

Haha! Love this so much. 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.

Thanks!

I am offloading all the storage to NSDocument, so I don't have to deal with stuff like this. :)

Re: Nerdy internals of an Apple text editor

#58
post #18

In the era of DOM documents (see notion, gitbook) I very often resort to attributed strings to do magic stuff with text parsing and manipulation. It’s such an elegant structure and I don’t understand why is so unknown. Incredible article btw

Thank you!

Re: Nerdy internals of an Apple text editor

#60
post #13
post #5

Are the internals of other Mac-native text editors like TextMate similar to this as well?

Depends on what you call “similar”. They’ll have storage, layout, a part of the layout that’s visible, etc, but they may not separate them that clearly, and won’t have that rich an API. TextView is way more flexible than what the typical _text_ editor needs. Text editors typically don’t need multiple fonts, multiple font sizes, varying line spacing, paragraph indents, proportional fonts, right-aligning or decimal tab…

Yep. TextView is a beast.

For multi-megabyte files I always use Sublime.

Post reply on HN