← All posts

Where does this link go? Zed's markdown preview wouldn't tell you

By ·

Hover a link in any browser and the destination appears in the bottom-left corner. It's such a standard affordance that you stop noticing it — until it's missing.

Zed's markdown preview had no equivalent. To find out where a link went, you clicked it, or you right-clicked and copied the URL. Both mean committing before you know.

The solution

Report URL hovers from the markdown renderer, then display the hovered destination using the existing LinkPreview component in the bottom-left corner — the same convention Firefox uses.

The part that was actually hard

Text links are straightforward: the text layout already knows what's under the pointer.

Linked images are not. An image sits outside the text layout, so the usual hit detection doesn't see it. That needed its own hit detection path — which is the same structural quirk behind making linked images clickable. Nested images keep being a special case because they live outside the system that handles everything else.

The other half of the work was clearing the preview at the right times. A hover indicator that gets stuck showing a stale URL is worse than none at all. It clears when the pointer leaves a link, when it leaves the preview entirely, and when the displayed markdown changes.

That last one is easy to forget. Scroll or re-render while hovering, and without it you'd be looking at the destination of a link that's no longer under your cursor.

Reviewing your own UI work

The test plan I wrote was mostly about disappearing, not appearing: move away from links, move outside the preview, change the document. Anyone can verify the happy path. The bugs live in teardown.

Merged as zed-industries/zed#60942.