# editor: Fix inconsistent search behavior for untitled/temporary tabs \(\#37086\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/69bdef38ecef673609e1acf1e7a6d79f5d4d44d3)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 69bdef38ecef673609e1acf1e7a6d79f5d4d44d3

Requested commit: 69bdef38ecef673609e1acf1e7a6d79f5d4d44d3

Commit: 69bdef38ecef673609e1acf1e7a6d79f5d4d44d3

Tree: c1ff1b608f4e8b579ed229cd9349c2d302b1822e

Author: Liu Jinyi

Committer: GitHub

## Message

````
editor: Fix inconsistent search behavior for untitled/temporary tabs (#37086)

Closes #37597 

Release Notes:

- N/A

---


## Problem

When using "Tab Switcher: Toggle All", temporary files (untitled buffers
without associated file paths) cannot be searched by their displayed
content. This creates an inconsistent user experience where:

- **UI Display**: Shows dynamic titles based on the first line of
content (up to 40 characters)
- **Search Text**: Only searches for the static text "untitled"

### Example
- A temporary file containing `Hello World` is displayed as "Hello
World" in the tab
- However, searching for "Hello" in Tab Switcher returns no results
- Only searching for "untitled" will find this temporary file

## Root Cause

The issue stems from inconsistent title generation logic between display
and search:

1. **Display Title** (`items.rs:724`): Uses `self.title(cx)` →
`MultiBuffer::title()` → `buffer_content_title()`
- Returns the first line of content (max 40 chars) for temporary files
   
2. **Search Text** (`items.rs:650-656`): Uses `tab_content_text()`
method
   - Returns hardcoded "untitled" for files without paths

## Solution

Modified the `tab_content_text()` method in `crates/editor/src/items.rs`
to use the same logic as the displayed title for consistency:

```rust
fn tab_content_text(&self, detail: usize, cx: &App) -> SharedString {
    if let Some(path) = path_for_buffer(&self.buffer, detail, true, cx) {
        path.to_string_lossy().to_string().into()
    } else {
        // Use the same logic as the displayed title for consistency
        self.buffer.read(cx).title(cx).to_string().into()
    }
}
```
````

## Parents

- [0e33a3afe0f37b1a7a37fec6b068abe9dd984009](https://git.cafe/gitcafe/zed/commit/0e33a3afe0f37b1a7a37fec6b068abe9dd984009?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/69bdef38ecef673609e1acf1e7a6d79f5d4d44d3?format=markdown)
