Frederik Handberg

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
This is a different version of the Markdown editor I am building. In this version, I am setting the Markdown syntax to font-size 0.01pt and color to invisible. This is different from my other version where I remove the syntax entirely from the string. Then when I need to show the syntax, I insert it back again. This is quite a fragile way to do it. I'm sure I can make it work, but changing the font-size to make syntax invisible rather than removing is much safer... #dev
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