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
Turns out, it's not actually a re-rendering issue, but rather a problem with how I am storing the string. In the current version, I store the string in the ViewModel without any of the Markdown syntax. Then my code tries to re-parse the string. Obviously, the parsing does not work, because there is no Markdown in the string that can be parsed... The interesting thing is, that initially when I load the MD file, all the syntax is parsed correctly, but as soon as I type a character, the whole string gets replaced with a version that has all the syntax removed - this is what I call the collapsed version. I must store the expanded version (the one with all the Markdown syntax), because otherwise the styling is completely lost. But I also need a string without the syntax, as this is the one that should be displayed by default in the 'Live Preview' mode. **So, this is my plan...** I need to store two different strings: - Collapsed version (what user sees in the editor): `"Display & Remove Syntax"` - Expanded version (with syntax): `"# Display & Remove Syntax"` When I want to render the syntax (e.g. if user clicks in formatted text), I should use the expanded version. But I only want to show the syntax for that particular range, not for the entire string... View quoted note →
Here's the second attempt of building my live-preview #Markdown editor: I made some massive improvements! 🚀 In fact, I think the last bug to fix is caret navigation using arrow-right key. For example, if I navigate caret from left to right into a word with bold styling, it'll skip over the asterisks "**|word**" and move immediately to inside of range. It works fine when navigating caret from opposite direction (right to left)... It's a minor detail, but important for a good UX. #dev #macOS #AppKit #Swift #SwiftUI
This was my first attempt at building the same live-preview functionality as #Obsidian and Bear 2.0. These apps hide all #Markdown syntax by default, but then insert the syntax only when cursor is positioned inside a range of text with styling applied (e.g. bold or italic). For example, we have a word "hello" with bold styling. By default, no syntax is displayed – the word is just "hello". But when placing cursor inside the word "**h|ello**", the syntax is now displayed. My first attempt at building this functionality was **VERY** buggy. This was mostly because I ran into issues with SwiftUI's default behavior, where it re-rendered the text view. This messed up my code. #dev #macOS #AppKit #Swift #SwiftUI
Been working on the ‘Source’ mode for my #Markdown editor. It’s working well, though currently only basic formatting works like headings (level 1-6), **bold**, _italic_, and `inline code`. I’ve decided to get the ‘Source’ mode working perfectly before I begin the implementation of the ‘Live Preview’ mode. The ‘Source’ mode is also a live preview, as it shows the formatting but with the Markdown syntax as well. However, the ‘Live Preview’ mode works more like a WYSIWYG editor because it hides all the Markdown syntax. Next task is to get code blocks working, and afterwards, get images to be displayed correctly. The Markdown editor is fundamentally different from my block-based editor as Markdown is linear whereas my block-based JSON notes are divided into multiple blocks where each block is its own text view. Using separate text views makes it much easier to display images and to make them interactive (e.g. clicking an image makes it full screen), because I can place a SwiftUI image in between two text views. In the Markdown editor, I need to embed images into the actual text view. TextKit2 works well for this. I’ve made a working solution before using `NSTextAttachmentViewProvider`. #dev #macOS #AppKit #Swift #SwiftUI View quoted note →
Worked on a color picker today for my notes app. It's fully functional, except for the alpha/opacity slider. After that's implemented, I'll work on making the UI look nice. #dev #macOS #Swift #SwiftUI #AppKit image
Famous TikToker Dylan Page talks about how #TikTok is removing and hiding videos, and suspending accounts without any explanation given other than "violating community guidelines". This is a great example of why #Nostr is needed.
I just implemented a very essential feature in the notes app I'm building 😁 It's now possible to rearrange blocks by moving them up and down. Added two options to the context menu that appears when right-clicking a block: "Move Up" and "Move Down". This is currently implemented for image blocks, normal text blocks, and headings - so I still got a few more blocks to work on... Next task will be getting it to work in list blocks. #dev #macOS #AppKit #Swift #SwiftUI image
I have made it possible to switch tabs by pressing `Cmd+1` and up to number 9. Can also switch tab in either direction by using `Option+Cmd+Left-arrow` or `Option+Cmd+Right-arrow` Furthermore, it's now possible to select multiple files by pressing command while clicking. Makes it much easier to move multiple files together rather than having to move one file at a time. #dev I need to debug the preview overlay for tabs. I have now experienced multiple times, where the overlay is positioned incorrectly. It's supposed to be right below the hovered tab, but this is not always the case. It's a very unpredictable bug that happens rarely, but still very annoying. Especially because once it happens, it does not go away unless relaunching the app. I expect the reason to be the `GeometryReader` not calculating the position correctly. View quoted note →
For my notes app, I should make it possible to relocate multiple files instead of having to move one file at a time. It should be possible to command+click files to select multiple. Once multiple files are selected, clicking and dragging to relocate should also be possible. Basically, exactly like it works in Finder. #dev
Sometimes #Claude has a tendency to mix #UIKit and #AppKit. I experience quite often that it writes some code using methods from UIKit that just does not exist in AppKit...
Files and folders can now be relocated by drag and drop. Would be cool to have an animation that shows the files being moved from one folder to another. Something I could work on in the future... **TODO:** Currently the user must drop directly over a folder to relocate. Instead, dragging over a folder’s contents should highlight the parent folder’s background and allow the user to drop the dragged file or folder to relocate it. #dev #macOS #Swift #SwiftUI #AppKit
It's a beautiful day with blue sky and the sun is shining ☀️ image Today will be about implementing a solution to monitor changes to the filesystem. More specifically, my notes app needs to be able to know when the user modifies their Space vault from outside the app. Currently, the app will not update the list of files if the user manipulates the vault through Finder. E.g., if the user renames or deletes files in their Space vault. _(the vault is just the root folder containing all the files and directories in the Space)_ From the research I've done, it seems like `DispatchSourceFileSystemObject` is what I need to be using. #dev #macOS #Swift #SwiftUI #AppKit
I'm having a re-rendering issue in SwiftUI. - I have two windows open with the same Space in each. - I then change the name of the space in `LaunchView`. Now, only the frontmost window will be automatically updated to display the new name of the Space. However, the window behind does **NOT** update unless I hover above the button displaying the name. I have tried the `.id()` approach, but that didn't work. It's a minor problem, but it's still driving me crazy. Using `@Observable` in the ViewModel should take care of re-rendering the necessary parts in the UI. I just don't understand why it only works in the frontmost window...