Been fighting with
#AppKit and
#SwiftUI to solve a height calculation problem. Seems like sometimes AppKit does not realize that the height of the SwiftUI code block view has changed. This leads to a problem when the code block grows in height (e.g. when adding more lines) and then it eventually starts overlapping other elements in the Markdown editor.

I am using `NSTextAttachment` to embed an interactive SwiftUI view as a `NSHostingView` inside `NSTextView`. It's really powerful but I also find it so difficult to work with. Especially when needing to share states/updates between the `HostingView` and the `NSTextView` (which is the outer Markdown editor that the code block is embedded into).
Codex seems to have finally found a semi-working solution to the height calculation problem. At least it works when I open the MD file, close it and reopen, then I can add more lines in code block and the editor will correctly update its height to accommodate the growing code block.
However, if I just open the MD file immediately after having started the app, then begin adding more lines, it will not tell AppKit's `NSTextView` about the height changes leading to overlapping issues.
#dev #macOS