# code/editor/find/useFind (zidane-ui/code/editor)

Import: `import { … } from 'zidane-ui/code/editor'`. Source: [ui/src/code/editor/find/useFind.ts](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/useFind.ts).

## Functions

### `useFind`

Function.

Find state for a file view or a column of diffs: counts every match in the model, highlights
the rendered ones and scrolls the current match into view. Pass the result to `FindBar`.

```ts
function useFind(
  args: UseFindArgs,
): { asked: number; capped: boolean; caseSensitive: boolean; close: () => void; index: number; jumpTo: (q: string, o: FindOptions, at: Omit<LineMatch, 'end'>) => void; open: boolean; query: string; searching: boolean; setQuery: Dispatch<SetStateAction<string>>; show: () => void; step: (direction: -1 | 1) => void; toggleCase: () => void; total: number }
```

**Parameters**

- `args` (`UseFindArgs`): See [`UseFindArgs`](https://zidane.si/docs/reference/ui-code-editor-find-use-find.md#UseFindArgs).

**Returns** `{ asked: number; capped: boolean; caseSensitive: boolean; close: () => void; index: number; jumpTo: (q: string, o: FindOptions, at: Omit<LineMatch, 'end'>) => void; open: boolean; query: string; searching: boolean; setQuery: Dispatch<SetStateAction<string>>; show: () => void; step: (direction: -1 | 1) => void; toggleCase: () => void; total: number }`

Source: [ui/src/code/editor/find/useFind.ts:50](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/useFind.ts#L50)

## Interfaces

### `FindParts`

Interface.

One diff (or the file) to search: its lines and the part key its matches carry.

```ts
interface FindParts
```

**Properties**

- `lines` (`readonly FindLine[]`): The searchable lines (`fileLines`, `diffLines`).
- `part` (`string`): Ties matches to the rendered surface with the same `FindSurface.part`; `''` for a lone file.

Source: [ui/src/code/editor/find/useFind.ts:21](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/useFind.ts#L21)

### `UseFindArgs`

Interface.

What [`useFind`](https://zidane.si/docs/reference/ui-code-editor-find-use-find.md#useFind) searches, paints and scrolls.

```ts
interface UseFindArgs
```

**Properties**

- `fallback` (`(match: LineMatch, scroller: HTMLElement) => ScrollTarget`): Where a match's part is when its line is not rendered: an element, or an estimate.
- `parts` (`() => readonly FindParts[]`): The searchable model; only built while find is open.
- `scroller` (`() => HTMLElement | null`): The scroll box holding the surfaces.
- `smooth` (`boolean`): Ease the scroll to the current match over several frames; `false` jumps (reduced motion).
- `surfaces` (`() => readonly FindSurface[]`): Rendered surfaces, read at paint time.
- `version` (`unknown`): Bumps when `parts` would change (new file contents, new diffs).

Source: [ui/src/code/editor/find/useFind.ts:29](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/useFind.ts#L29)

## Types

### `FindState`

Type.

What [`useFind`](https://zidane.si/docs/reference/ui-code-editor-find-use-find.md#useFind) returns: open state, the query and match case, the current index and total
(`capped` when the total reads `N+`), and the actions `show`, `step`, `jumpTo` and `close`.

```ts
type FindState = ReturnType<typeof useFind>
```

Source: [ui/src/code/editor/find/useFind.ts:203](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/useFind.ts#L203)
