Textkit 2 for Scrivener?

I was curious what effect the recent (re)focus in macOS 12 and 13 on Textkit may have on Scrivener’s development?

Here is this year’s WWDC talk on Textkit 2, where they mention that RTF in Text Edit in macOS 13 will use Textkit 2:

As Scrivener’s editor is built on Textkit, I wonder if this renewed focus will actually cause problems if the behaviour changes. I think KB made a ton of changes and workarounds, and this may require sticking to a legacy mode? On the plus side if possible, Textkit 2 supports more advanced image+text wrapping, better line breaks, improved lists etc.

@KB will be the one to answer this, though he is currently fully occupied doing something major in his code bunker so I expect we’ll have to speculate a bit here…

Actually I’ve spent the past few days familiarising myself with TextKit 2, given that TextKit is my bread and butter. (I learned a little last year, but it was nowhere near ready for use in text views back then.)

The short answer is that in the short term it won’t make much difference at all - Scrivener will continue using TextKit 1 for a good while yet, probably for a few years. TextKit 2 is clearly the future but it’s not yet ready for use in anything but fairly simple text editors. (I’m talking about using it with NSTextView and UITextView here, Apple’s standard editors - you could probably do quite a lot with TextKit 2 if you were insane enough to build your own editor from scratch.)

Although it was stated in the WWDC 22 video that TextEdit now uses TextKit 2 “everywhere”, for example, that’s not quite true. If you switch to Wrap to Page view in TextEdit, it reverts to TextKit 1, and for good reason: multi-page layouts are not yet possible in TextKit 2. TextKit 2 doesn’t support printing yet, either.

And it’s not quite right that TextKit 2 has “improved” support for lists - the support is much the same (theoretically) as in TextKit 1, except that it introduces lists to iOS too. However, currently that support is vary buggy. If you try creating lists in TextEdit on Ventura, you will see they aren’t quite ready yet. Hitting tab to indent a list breaks the app and makes the text uneditable.

Also, TextKit 2 doesn’t yet support tables. (Try adding a table in TextEdit on Ventura and the tables palette appears but no table is added. Switch to Wrap to Page mode - and thus TextKit 1 - and tables work fine. Switch back again and all of the text disappears.)

There’s a bunch of other stuff TextKit 2 can’t do yet, too. For instance, there’s currently no way of overriding the insertion point (the caret or blinking cursor) drawing, which means that there’s no way of providing a block cursor or a thicker cursor. And because TextKit 2 still has TextKit 1’s annoying issue whereby the cursor is twice the size of the text when you use double line spacing, without being able to override the drawing, there’s no way of fixing it as I do in Scrivener with TextKit 1.

I have filed about twenty bugs and enhancement requests with Apple over the past few days, in addition to the ones I filed last year - the TextKit team are going to love me. :slight_smile:

If all that sounds very negative, it’s only because TextKit 2 is still at such an early stage. For developers who just need a fairly standard text view with a bit of text customisation or syntax highlighting, it will work well already. For us we need a lot more. However, I do like it so far, and it won’t require a complete rewrite. The back end text storage remains the same, and that’s what we use to manage scrivenings and word counting, for instance, so there’ll only be slight modifications there.

And on the UI side the same NS/UITextView is still used, albeit with some differences in behaviour depending on the version of TextKit you use. It’s all the stuff in between, the code that lays out all of the text and customises its appearance that is different - and that is still a lot of code for us.

Still, over the past few days I managed to get a sample app working with our scrivenings code, implement “show/hide invisibles” the TextKit 2 way, add a bunch of custom attributes and more. I’ve built myself a sample app with all of this code and a whole bunch of notes, so that I can refer to it when the time comes to switch.

The short version: TextKit 2 isn’t ready for Scrivener yet, but we’ll almost certainly be adopting it when it’s more mature.

6 Likes

Well, at least now (FINALLY), they’re paying attention to Text Kit. I hope your feedback really makes them flesh it out and make it extensible in ways that’ll make it less of a pain to work with from both a dev and a user perspective. Especially when it comes to lists and tables.

Also, does anything they’ve done with TextKit2 allow a programmer to swap out custom dictionaries/word lists? I’ve seen (and made) requests to be able to keep a custom set of spelling words isolated to a project, rather than adding them to the system’s dictionary.

Nothing yet, because the changes are all under-the-hood layout stuff, and nothing to do with how you interact with the dictionaries or anything like that, I’m afraid, all of which remains a black box for the most part.

Will this allow users to change the size of fonts in the UI?

I’m not quite sure what you mean there - you can already change the size of fonts in the UI, and TextKit 2 works the same in that regard.

@KB Educated guess that it is a reference back to this recent discussion. Inspector Panels font size too small

Bingo, you got it (extra for 20 minimum)

@KB, wow thanks for that deep dive, very interesting! IIRC Nisus and some others also uses TextKit, so hopefully between you all, you can push the Textkit developers with your swarm of bugs and enhancements :nerd_face:

As @Rdale mentions, overall it is great news for us Scrivener users that Textkit is getting Apple’s attention in terms of active development across macOS and iOS, even if not much will be useable in the shorter term…

For anyone interested, some thoughts and a couple of videos here:

… and

1 Like