
# Search

`search` adds a Search icon to the activity bar with a view that searches every file in the
workspace. Without this extension, the workbench has no Search icon at all.

```ts
import { search } from "codelet/extensions/search";
import { Workbench, FileSystem } from "codelet/workbench";

const workbench = new Workbench({
  parent: document.getElementById("app")!,
  fs: new FileSystem({ "/README.md": "# Hello" }),
  extensions: [search],
});
```

`search` takes no options.

## Try it

Click the Search icon in the activity bar and type `greet`.

::codelet-playground{mode="workbench" extensions="search" view="search" height="420"}

```ts [greet.ts]
export const greet = (name: string) => `hi ${name}`;
```

```ts [index.ts]
import { greet } from "./greet";

console.log(greet("codelet"));
console.log(greet("reader"));
```

```md [README.md]
# greet

A greeting, and a second mention of greet in prose.
```

::

## What it searches

Typing in the filter box runs a case-insensitive substring search over every file's text, and
over file paths. The view re-runs the search whenever a file changes or is deleted, and starts
empty: nothing is listed until you type.

## Reading the results

Results are listed as a tree, one row per file with a match under it for each line. Clicking a
match opens its file with the line selected. A file listed only because its path matched, and
not its contents, opens directly instead of expanding.

The view's message line above the results reports how many results were found, in how many
files. A search stops after the first 500 matches and says so, rather than silently truncating.

## The row menu

A right-click on a result opens three items:

| Item          | On         | What it does                                                                   |
| ------------- | ---------- | ------------------------------------------------------------------------------ |
| **Open File** | A file row | Opens the file. A file with matches expands on a click, so this is the way in. |
| **Copy**      | Either     | The file's path, or the matched line.                                          |
| **Dismiss**   | Either     | Takes that row off the list.                                                   |

Dismissing is about the answer on screen, not about the file: the next search — a keystroke, an
edit, a file deleted, or a new list of references — brings every row back.

The browser only gives a page a clipboard in a secure context, so a workbench served over plain
http shows no **Copy** item at all rather than one that silently does nothing.

:read-more{to="/extensions"}
