Frederik Handberg
banner
frederikhandberg.com
Frederik Handberg
@frederikhandberg.com
🇩🇰 23. Studying for a degree in Software Engineering, while working as a Freelance News Photographer. I'm also learning to sew garments...
In the video, the red borders show the boundaries of each text view. Notice how I'm able to move between them seamlessly, as if it were one continuous editor.
December 8, 2025 at 8:55 PM
My solution lets the user move the caret smoothly between text views just by using the arrow keys. On top of that, the implementation also supports making text selections across text views.

The user can even copy text from a selection that spans multiple text views.
December 8, 2025 at 8:55 PM
The problem is that by default #macOS doesn't natively support caret navigation or text selection across multiple text views. This would be a big problem for the user experience in my app, so I had to build a solution!
December 8, 2025 at 8:55 PM
Luckily, I figured out a solution based on `INDSequentialTextSelectionManager`.

GitHub repository:
github.com/indragiek/IN...
GitHub - indragiek/INDSequentialTextSelectionManager: Sequential text selection for NSTextViews
Sequential text selection for NSTextViews. Contribute to indragiek/INDSequentialTextSelectionManager development by creating an account on GitHub.
github.com
November 26, 2025 at 2:34 PM
An example of this is text selection:

The problem with having separate and independent text views is that selecting text across multiple `NSTextView`s is not natively supported.
November 26, 2025 at 2:34 PM
Though, I’m not saying that having separate text views is solving all problems, because it does indeed create its own set of problems that must be fixed to ensure a good user experience.
November 26, 2025 at 2:34 PM
I have tried to combine all block types in a single `NSTextView`, but it gets problematic converting the JSON structure to `NSMutableAttributedString` because the ranges gets screwed up very easily.
November 26, 2025 at 2:32 PM
I’m building a block-based notes app.
My idea was to have a separate text view for each block type.

For example, a heading block would have its own text view.
Likewise, a normal paragraph block would also have its own text view.
November 26, 2025 at 2:32 PM
However, now I just found a #GitHub repository that might be a solution:
github.com/indragiek/IN...

It's old and uses Objective-C, but Sonnet 4.5 should be able to help port it to Swift.
GitHub - indragiek/INDSequentialTextSelectionManager: Sequential text selection for NSTextViews
Sequential text selection for NSTextViews. Contribute to indragiek/INDSequentialTextSelectionManager development by creating an account on GitHub.
github.com
November 22, 2025 at 8:46 PM
This led me to implement a different solution where I used a single `NSTextView` for all blocks rather than separate.
November 22, 2025 at 8:46 PM
This is obviously part of learning, but it still sucks when you think what you just made is really good, and then it turns out it has massive flaws because you just didn’t know any better 😅
November 20, 2025 at 4:20 PM
For example, with the notes app I’m building, I’m making so many assumptions about how things should be done. And I’ve had to redo implementations again and again because I realized my approach was bad.
November 20, 2025 at 4:20 PM
**Previous development update:**

bsky.app/profile/fred...
Apparently, `NSTextAttachment` is very limited in what it can do. Simple things like opacity and scale hover effects aren't possible by default. That's a bummer... 😔
#dev #Swift #SwiftUI #AppKit
I finally figured out a solution to fix the many issues I had with my approach for the editor 😅

Basically, I was using an independent and separate `NSTextView` inside of each block. For example, if I had two text blocks, it would be two separate `NSTextViews`.

#dev #Swift #AppKit #SwiftUI
November 15, 2025 at 4:43 PM
**Hover effect bug:** There's also a problem with the text selection cursor showing even when I'm hovering over an image - it should change to the pointer cursor. It does actually change very briefly, but then changes back to text selection cursor again.
November 15, 2025 at 4:42 PM
**Re-rendering bug**: You'll notice in the video, that the images are showing the loading indicator very briefly whenever I hover over the heading blocks. This will be my next task to fix.
November 15, 2025 at 4:42 PM
My biggest problem was getting the size of the images to work. They seemed to be limited to the line height, which meant, the images couldn’t grow more in height than 32pts.
November 15, 2025 at 4:42 PM
The migration to the new `TextKit2` went fairly smooth, but getting the images to show correctly inside the `NSTextView` was quite the challenge 😅
November 15, 2025 at 4:42 PM
However, by using this new API, I had to migrate from `TextKit1` to the newer version `TextKit2`.
November 15, 2025 at 4:42 PM
I tried to write some hacks to get it working, but then I learned about the newer API called `NSTextAttachmentViewProvider` which would allow me to do exactly what I wanted - to embed a SwiftUI image inside a textview.
November 15, 2025 at 4:42 PM