qeude / SwiftDown

📦 A themable markdown editor component for your SwiftUI apps.
MIT License
472 stars 50 forks source link

Odd behavior with SwiftDown inside a NavigationSplitView #31

Closed garrettmurray closed 8 months ago

garrettmurray commented 8 months ago

Describe the bug I started attempting to integrate SwiftDown into a cross-platform SwiftUI project that utilizes a NavigationSplitView, and noticed an odd behavior where SwiftDown seems to always be referencing an older item. I've tried many different variations of utilizing NavigationSplitView, but all of them exhibit this issue. If I use the deprecated NavigationView instead, this problem does not occur.

To Reproduce Here's some sample code to show off the issue: https://gist.github.com/garrettmurray/4e23b2478f89beae47913a78d9c194a2

You'll note that only the SwiftDown field suffers from this issue—editing via the TextEditor in the same VStack appropriately updates the correct, currently-selected item.

Expected behavior SwiftDown field would edit the correct item's text, like TextEditor does.

Screenshots Attaching a video of this bug in action as well, using the sample code linked above.

https://github.com/qeude/SwiftDown/assets/6025/b345b512-37e8-4a1a-b5ad-5431ec83aa6e

Desktop (please complete the following information):

qeude commented 8 months ago

👋 Hey, thanks for your feedback! It seems like adding an .id on the SwiftDownEditor that depends on your Item would fix that. I don't have an idea on how I could fix that from the package for now to be honest

garrettmurray commented 8 months ago

👋 Hey, thanks for your feedback! It seems like adding an .id on the SwiftDownEditor that depends on your Item would fix that. I don't have an idea on how I could fix that from the package for now to be honest

It's hilarious how simple this solution is, and, of course, completely resolves the issue. I was so deep in NavigationSplitView insanity in this project that I completely missed it. Thank you!