Behind the scenes, "plain" text editing is unbelievably complex and weird

For some reason I’m reminded of Fermat’s “I have discovered a truly remarkable proof of this theorem which this margin is too small to contain”; but more of a “I have discovered a truly remarkable proof of this theorem that this program is too broken to render.”

4 Likes

Yes, but many apps want text editing plus a little extra. Sometimes the OS text editing system is flexible to handle it, sometimes not. For example Apple’s is imperfect, but on iOS it allows you to add extra tools in a bar above the keyboard (but it doesn’t have a great answer on how to access those if you use a bluetooth keyboard and dismiss the on screen one). It also edits NSAttributedText do you can change fonts, boldness, kerning parameters, and many other things. If you want to embed things like a math formula it gets a lot harder, but you can either render it to an image and use an NSTextAttachment to display it, but that embeds it as a non-editable item. Actually writing code that allows a user to interact with an embedded element like that is even more painful.

So it is decent for “type some text and I’ll make a really big version of it and scroll it!”, but it is less great for “Yo, type an equation and Ill solve it!”

I think they use the NSTextLayoutManager with some custom policies (the layout manager has a lot of delegates and other customization points). That is a standard utility on macOS, but it wasn’t exposed on iOS, and only the subset that Safari needed was brought over, at least for a long time. Around iOS 9 or so it was more fully ported and exposed as public API. My timelines may be off. I have never actually used it on iOS, although I do use it on macOS as part of driving a laser cutter.

You are far too late brother, dogs have already zero width joined with the safety vest in the abomination known as the “Service Dog”.

I fear for our future.

This topic was automatically closed after 5 days. New replies are no longer allowed.