Thread

Zero-JS Hypermedia Browser

Relays: 5
Replies: 1
Generated: 17:17:27
I FINALLY have `NSTextAttachmentViewProvider` working in my native #macOS notes app! 🎉 This means I can now display interactive #SwiftUI views inside an `NSTextView`. Notice how I’m embedding an image directly into the textview, which the user can click to show the image in a popup. https://video.nostr.build/d5113f80248fa1420f4d6cd37035d42d1938c1c0d79209e1623ea6e229991214.mp4 It sure did take a lot of trial and error before I could get it working. I did try to use LLMs to help out, but they were hallucinating like crazy - this makes sense though. They learn from gathering data, but there really isn’t much data available online about `NSTextAttachmentViewProvider`. This is unfortunately the case with many of the #AppKit APIs… There just aren't that many resources to be found, which makes learning AppKit much harder compared to, for example, web development (at least I personally found web dev much easier to learn). **The problem I experienced:** The whole point of me trying to use the API, was because I needed to display a SwiftUI view containing an image directly inside an `NSTextView`. This is unsupported by the `NSTextAttachment` API. _Just to be very clear: Yes, I know that you can show an NSImage using `NSTextAttachment`, but you **CANNOT** show a SwiftUI image._ 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. However, by using this new API, I had to migrate from `TextKit1` to the newer version `TextKit2`. The migration to the new `TextKit2` went fairly smooth, but getting the images to show correctly inside the `NSTextView` was quite the challenge 😅 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. **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. **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. #Swift #dev
2025-11-09 16:32:25 from 1 relay(s) 1 replies ↓
Login to reply

Replies (1)

**Previous development update:** nostr:nevent1qqswa5d8jz42aqr0atxaqssfnrhjjm6wewam9gk80sfkvct636s7q4szyzwflq0d090s7hh62kyn9qjxslvyl3lx5n86dk6ad5a4pl9hl7hvyqcyqqqqqqgprpmhxue69uhhyetvv9ujuumwdae8gtnnda3kjctvqy28wumn8ghj7mn0wd68ytn00p68ytnyv4mqz9nhwden5te0wfjkccte9ehx7um5wghxyctwvs9vnm3g
2025-11-09 16:39:22 from 1 relay(s) ↑ Parent Reply