Frederik Handberg's avatar
Frederik Handberg
npub1nj0c...2gqz
23 🇩🇰 Studying for a degree in Software Engineering while building fun projects and working freelance as a News Photographer 📷 I share my software projects, photos and videos from my work as a news photographer, and progress updates as I learn to sew garments. Basically, I just write about my hobbies. frederikhandberg.com
I love that #programming is all about problem solving. That’s what makes it so fun. At the same time, it can also be a disadvantage. Sometimes, I’ll run into a bug and spend days trying to solve it. This can be super frustrating 😫 But then it finally works, and the adrenaline kick feels amazing 🚀
My previous approach for the editing experience in my notes app was using multiple independent `NSTextView`'s. This caused a problem where I was unable to perform text selection across multiple blocks, since the blocks were in separate `NSTextView`'s. This led me to implement a different solution where I used a single `NSTextView` for all blocks rather than separate. However, now I just found a #GitHub repository that might be a solution: It's old and uses Objective-C, but Sonnet 4.5 should be able to help port it to Swift. Previous post: View quoted note →
A massive challenge for a #programmer like myself without years of experience is that I don’t really know how things are done. 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. 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 😅 #dev
After learning the shortcut `CMD + Shift + O` my #Xcode experience has improved significantly. It’s exactly like the `CMD + P` shortcut in #VSCode. Just a way to search for files to quickly open them.
🚨 I have an #AppKit pro tip for y’all that I just learned!!! 🚨 If you have an `NSView` above an `NSTextView` and you want to change `NSCursor` when hovering the `NSView` to something like `NSCursor.pointingHand`, you need to make sure you don't call `super.mouseMoved(with: event)`. If you call `super` on your `mouseMoved` event, it will override the `NSCursor` to the default. The default `NSCursor` for `NSTextView` is the `NSCursor.iBeam`, so you will experience the pointingHand to show very briefly, but then immediately be changed to the iBeam when you hover over the `NSView`. I have spent the past three hours trying to figure out a solution to the cursor flickering and I literally just fixed it. #dev #Swift #AppKit
Haven’t used the @Damus client in a long time, but I just tried it out again. When writing a note, I noticed a bug where the caret will jump to the end whenever clicking return to make a line break. #Damus #bug
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. 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
View quoted note → View quoted note → It’s hard to get normies on #Nostr. As soon as they learn that their NSEC can’t be recovered or reset, or that discoverability on Nostr is mostly non-existent (except for reposts), they’ll be heading for the exit… The problem with Nostr identities not being recoverable if compromised is a massive problem. It’s my biggest problem with the Nostr protocol. It only takes one mistake where the user pastes their NSEC into a malicious client. As Nostr grows (if it ever does), we will see an increase in malicious clients popping up. Think about building up a following on Nostr just to lose it all because you made one mistake pasting your NSEC into the wrong client. It’s discouraging to creators…
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... 😔 Luckily, I just learned about `NSTextAttachmentViewProvider`, and this one seems to support embedding interactive views in text. This means, I should be able to have a SwiftUI view embedded directly in the `NSTextView`. This SwiftUI view will contain an image with some beautiful animations such as: ```swift .opacity(isHovering ? 0.85 : 1.0) .scaleEffect(isPressed ? 0.97 : 1.0) .animation(.easeInOut(duration: 0.15), value: isHovering) .animation(.spring(response: 0.2, dampingFraction: 0.6), value: isPressed) ``` #dev #Swift #SwiftUI #AppKit View quoted note →
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 `NSTextView`s. This was causing issues with caret navigation using the arrow up and down keys. The reason was that the textviews weren’t connected in any way, so I had to implement a custom solution. It mostly worked, but the x-position was sometimes off by a few characters. Another problem was selecting text across multiple blocks. This isn’t possible by default either. I didn’t try to implement a custom solution for this, because I could already see that my approach of using separate textviews was flawed. I would’ve ended up spending a lot of time fixing basic things like text selection not working. I then thought, _what if I could just use a single textview?_ I realized that using `NSMutableAttributedString` could be useful. I spent all of Sunday working on this, but I finally have a solution that seems pretty solid. Now all blocks are displayed in the same textview, so selecting text across multiple blocks finally works 🚀 **Next tasks:** - Get images and videos working using `NSTextAttachment`. - I also need to get the animation working when collapsing a heading, so that the text moves up and its opacity decreases. - The pointer cursor does not show correctly when hovering the ellipsis button. It still shows the text selection cursor. #dev #Swift #AppKit #SwiftUI View quoted note →
In the current approach, I use an `NSTextView` in each block. This means, if you have two text blocks, there are going to be two separate `NSTextView`s. This is problematic, as it’s really difficult to make keyboard navigation feel natural when navigating the caret between the two text blocks. You know how when you use arrow up and down keys to navigate in some text, the x-position is remembered to ensure the caret stays in the same position on the horizontal axis. I do have a solution that mostly work, but I have a bug where _(I think)_ it resets the x-position on each up and down click. Shouldn’t be too difficult to fix. **However, there is another problematic issue:** Another problem is text selection. Selecting text across two different `NSTextView`s must be faked, as it does not work by default, so I need to implement a custom solution. **I see two options:** - I can continue with the current approach of using separate `NSTextView`s for each block, but this requires much debugging and custom solutions. Maybe I will never be able to get it perfect 🤷‍♂️ - Or, I can pivot and use one single NSTextView which is apparently what Apple Notes is doing. I’m not super familiar with `NSMutableAttributedString` and `NSAttributedString`, but apparently these allow for custom styling inside the same text string. For example, you can have a line with a bigger font size and then a line below with a smaller font size inside the same text paragraph. You can even add attachments inside the text with `NSTextAttachment`. I think this should also work for checkboxes. I will experiment with this new approach over the weekend. Hopefully, I can get something working. #dev #macOS #Swift #AppKit View quoted note →
I added a new image popup to my #macOS notes app 🚀 Simply click on an image, and it will open the image in a popup with a blurry and slightly dark background. I think it looks beautiful 🤩 Also added a subtle fade-out effect to the note content right below the tabs at the top. Can't wait to begin working on the iPhone and iPad app, but there's still more to be done on the macOS version 💻 I still need to implemented the visual canvas functionality, which will be a major part of the app. I think it will be perfect for brainstorming and organizing notes. The home tab also needs to be implemented. Right now, there’s just placeholder text. Still figuring out exactly what I want with it 🤔 #dev #Swift #AppKit
Funny how in autumn I get way more productive. I just code all the time 😂 And besides coding, I walk the dog 🐕‍🦺 The weather outside is cold and it’s raining 🌧️ Not very fun to be outside this time of the year…
Importing images and videos is now working in my notes app 🚀 But it's not quite perfect yet! There's still more work to do 💻 When importing media for the first time, an `/assets` folder is created in the root directory where all media is saved. Media files are reference by relative paths in the note documents. Need to work more on videos (notice the black bars on top and bottom - they should be removed). When placing cursor on video and then swiping up and down, the video starts scrubbing which is annoying. Need to figure out how to disable that. Resizing images and videos doesn't work. I also need to get fullscreen working. Basically, when double-clicking on an image, it should go into "fullscreen" - well, more like a popup with a blurry and dark background. I should probably add an option in the context menu when right-clicking an image to make it a fullscreen image that fills the entire screen. Two more options I should add could be "Open image in new tab" and "Reveal in Finder". This is unrelated to media and is more of a general issue: There's a problem with the 'Files' sidebar not updating/re-rendering when new files are imported. It just does not render the new files, so they are never displayed in the sidebar, unless the user quits and reopens the app. I think this should be fairly easy to fix. I probably just forgot to observe an `NSNotification`... #dev #Swift #AppKit #macOS View quoted note →
Today, I'm going to be working on the functionality to insert media like images and videos into documents for my notes app. I'll concentrate on getting images working, but maybe I can even get support for videos implemented as well before the end of today. **I have some decisions I need to make:** - Where should media be saved? I'm thinking of creating an `/assets` folder automatically when the user imports some media. - How should notes reference media? Should probably be the same way as Obsidian - just use a relative path. However, it's important that the path updates automatically if the user moves the media file elsewhere. - What to do if there's a naming conflict? Either, the app can check if the imported media is identical - in that case, there's no reason to import a duplicate so just cancel the import and let the user know, that the media has already been imported. Otherwise, I could just add "(1)", "(2)" and so on after the file name. The last option is certainly easier, so I think I'll start with that, then I can improve it later... Hopefully I can get it working before the end of today 🤞
Exactly! Algorithms aren’t necessarily bad. However, the user **MUST** always be in control. This is the problem with centralized platforms. They give no control to the user. All users on a platform like TikTok are forced to use their addictive algorithm designed to steal their attention for as much time as possible. View quoted note →
I changed the UI a bit for my native #macOS notes app 🚀 Now the note documents are displayed inside what looks like a page. I personally really like the design, but it’s just an option the user can toggle. If disabled, the note shows without the page outline. **What I have fixed:** - Indentation now works in lists. Using tab to indent and Shift+Tab to unindent. - Deleting list items is now possible with backspace. If the item has text, it’s transformed into a normal text block. If empty, the list item is removed. - Collapsible headings. - Added a translucent background color when hovering blocks. - Improved caret navigation between blocks. It feels much more natural now because the app remembers the x-position, so the caret stays in the same place on the x-axis when moving between text blocks with the arrow keys up and down (not implemented for lists yet). **Next task:** Implement functionality to delete blocks. I also need to figure out how to show the text formatting options. I see two options: 1. Either show a toolbar 2. Or show all the formatting options in a sidebar #Swift #AppKit #dev
Also, I’m not sure how many so-called “content creators” or influencers actually want to build a following on #Nostr, knowing that if they lose their private key or if it gets compromised, they’re just shit out of luck. There’s nothing they can do. Of course that turns people away. View quoted note →