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
