Me porting Runestone from UIKit to AppKit.

Yay! Runestone now works with... *Checks notes*... UIKit?? 🤨

In order to prepare for AppKit support, I had to rip the internals of Runestone apart and put it together again. For the first time in 36 hours, Runestone now works with UIKit again.

So I now have an NSWindow with an NSView that receives keystrokes. That's like step 0 in building a text editor, right?

There's such a long way to go still before Runestone is rewritten in AppKit. I hope I'll eventually turn a corner where all my work from UIKit can be reused and I ✨magically✨ have an AppKit implementation.

Runestone just rendered its first text using AppKit. Baby steps, y'all.

The AppKit version of Runestone now supports scrolling the content.

This involves a bit more than just wrapping everything in an NSScrollView because Runestone only renders the lines within the viewport.

Baby steps, y'all.

Time to add a caret that shows where characters will be inserted. I'm a little bummed that I have to implement this myself. We get that for free in UIKit.
Runestone for AppKit now has a caret. Baby steps, y'all.

I need to implement all moving within lines myself 😑

In the screenshot I'm logging the selectors that I don't handle but that AppKit expects me to handle. This is something we get (almost) for free in UIKit. Honestly, I really don't want to write this logic.

@simonbs NSTextView handles these, of course. Are you writing a a replacement NSView, or using Catalyst and finding that UITextInteraction in Catalyst doesn't handle them correctly?
@steveshepard I’m subclassing NSView and conforming to NSTextInputClient. I’m essentially trying to do what I’ve done with UIView and UITextInput but in AppKit.
@steveshepard I’m curious to know which approach you’re taking with Storting. Is it AppKit or Catalyst?
@simonbs On macOS, Storyist uses NSTextView. Writing a replacement for that is a lot of work. Unfortunately, NSTextInputClient only gets you a small subset of what UITextInput get you on iOS and there isn't a UITextInteraction equivalent.
@steveshepard Yeah, it seems to be a lot of work. But you are also using Core Text on iOS, right? Can you reuse that with an NSTextView?
@simonbs Yes, CoreText on iOS, implemented in the days before TextKit came to the platform. I don't currently use CoreText on macOS because NSTextView is pretty complete (and extensible).
@steveshepard Hmmm… I fear I’ll end up with vastly different implementations if I go that route. Maybe I made a mistake to go with Core Text over TextKit when I started the project. TextKit just had some performance issues that I couldn’t live it 😕
@simonbs Yes, they'll be quite different. I think @krzyzanowskim has an NSTextView replacement, so if you're going to invest the effort, that might be a place to start.