Skip to content

markdown_preview: Show directory for preview tabs when tab title is ambiguous - #65736

Merged
SomeoneToIgnore merged 5 commits into
zed-industries:mainfrom
gitKashish:fix/markdown_preview/disambiguate-tab-titles
Oct 19, 2026
Merged

SomeoneToIgnore merged 5 commits into
zed-industries:mainfrom
gitKashish:fix/markdown_preview/disambiguate-tab-titles

Conversation

@gitKashish

Copy link
Copy Markdown
Contributor

Summary

Closes #65528

Previewing two files with the same name (e.g. docs/README.md and guide/README.md) showed two tabs both titled Preview README.md, with no way to tell them apart.

Panes disambiguate tabs by calling Item::tab_content_text with an increasing detail until the titles differ, then pass the chosen level to tab_content. MarkdownPreviewView::tab_content_text ignored detail, so the pane never got past level 0.

  • tab_content_text now asks the source editor for its title at the requested detail and prefixes Preview . Without a name clash it's unchanged (Preview README.md).
  • tab_content shows the parent directories after the title as a small muted label, like editor tabs. For that, the description logic in Editor::tab_content moved into a new public Editor::tab_description, which both use, so editor tabs render exactly as before.
  • In the tab switcher (truncate_title_middle), the preview row now shrinks and truncates the same way editor entries do.

The preview still doesn't report a project path, so navigation history and reopening closed tabs are unaffected.

image

Testing

  • Added preview_tabs_for_files_with_the_same_name_show_their_directory, which previews docs/README.md and guide/README.md in one pane, runs the pane's disambiguation (workspace::tab_details) and checks the titles are Preview docs/README.md and Preview guide/README.md (using path! so it works on Windows). It fails without the fix.
  • Manually tested on Linux: two previews of README.md from different directories show docs / zed after the title, matching the editor tabs; the tab switcher entries truncate like editor entries.

Self-review

  • I've reviewed my diff for quality, security, reliability, and performance.
  • UI changes follow the checklist.
  • Tests cover the new or changed behavior.

Release Notes:

  • Fixed Markdown preview tabs for files with the same name not showing their directory.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Oct 16, 2026
@gitKashish gitKashish changed the title fix(markdown_preview): show the directory in tabs for previews of fil… Markdown Preview: Show directory for preview tabs when tab title is ambiguous Oct 16, 2026
@gitKashish gitKashish changed the title Markdown Preview: Show directory for preview tabs when tab title is ambiguous markdown_preview: Show directory for preview tabs when tab title is ambiguous Oct 19, 2026
@SomeoneToIgnore SomeoneToIgnore added area:ui/tabs Feedback for tabs behavior, navigation, style, etc area:preview/markdown Feedback for Zed's Markdown preview labels Oct 19, 2026
@SomeoneToIgnore SomeoneToIgnore self-assigned this Oct 19, 2026

@SomeoneToIgnore SomeoneToIgnore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, a few notes.

// shown in the description rather than in the title.
.child(
Label::new(self.tab_content_text(params.detail.unwrap_or_default(), cx))
Label::new(self.tab_content_text(0, cx))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editor::tab_content_text(0) can return a full path for single-file worktrees with an empty relative path (items.rs:2336–2343).
For an external /tmp/out/README.md, the new code supplies Preview /tmp/out/README.md as the primary label and /tmp/out again as the subtitle, without any collision.

Keep the path-aware key for disambiguation, but build the displayed label from editor.title(cx), matching the existing editor rendering.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Fixed, the title now uses editor.title(cx). MB I didn't consider external files.

Comment thread crates/editor/src/items.rs Resolved

@SomeoneToIgnore SomeoneToIgnore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you for the context on the new API.

One more findings meanwhile.

@SomeoneToIgnore SomeoneToIgnore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for all the fixes!

@SomeoneToIgnore
SomeoneToIgnore added this pull request to the merge queue Oct 19, 2026
@gitKashish

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, learned a lot from it!

Merged via the queue into zed-industries:main with commit 60e8c18 Oct 19, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preview/markdown Feedback for Zed's Markdown preview area:ui/tabs Feedback for tabs behavior, navigation, style, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown preview tabs with the same filename don't distinguish by directory path

2 participants