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

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

## Functions

### `diffLines`

Function.

A diff's lines in the order the unified view shows them: context, then each change's deletions and additions.

```ts
function diffLines(diff: FileDiffMetadata): FindLine[]
```

**Parameters**

- `diff` (`FileDiffMetadata`): The parsed diff of one file.

**Returns** `FindLine[]`

Source: [ui/src/code/editor/find/find-model.ts:74](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L74)

### `fileLines`

Function.

A file's lines, numbered from 1.

```ts
function fileLines(contents: string): FindLine[]
```

**Parameters**

- `contents` (`string`): The whole file; `\r\n` endings are stripped.

**Returns** `FindLine[]`

Source: [ui/src/code/editor/find/find-model.ts:65](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L65)

### `findAll`

Function.

Every match across `parts` in order, capped at `MAX_FIND_MATCHES`. `capped` says the cap cut the
search short.

```ts
function findAll(
  parts: readonly { lines: readonly FindLine[]; part: string }[],
  query: string,
  opts: FindOptions,
): { capped: boolean; matches: LineMatch[] }
```

**Parameters**

- `parts` (`readonly { lines: readonly FindLine[]; part: string }[]`): The lines to search, grouped by the diff (or file) they belong to.
- `query` (`string`): The literal string to look for.
- `opts` (`FindOptions`): Case sensitivity.

**Returns** `{ capped: boolean; matches: LineMatch[] }`

Source: [ui/src/code/editor/find/find-model.ts:107](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L107)

### `matchesIn`

Function.

Every occurrence of `query` in `text`, as UTF-16 offsets. Matches don't overlap; an empty
query matches nothing.

```ts
function matchesIn(
  text: string,
  query: string,
  opts: FindOptions,
): { end: number; start: number }[]
```

**Parameters**

- `text` (`string`): The text to search, such as one line.
- `query` (`string`): The literal string to look for (not a pattern).
- `opts` (`FindOptions`): Case sensitivity.

**Returns** `{ end: number; start: number }[]`

Source: [ui/src/code/editor/find/find-model.ts:39](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L39)

## Constants

### `MAX_FIND_MATCHES`

Constant.

Searching stops here: past it the count reads `N+` and painting stays cheap.

```ts
const MAX_FIND_MATCHES = 5000
```

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

## Interfaces

### `FindLine`

Interface.

One searchable line of a file or diff, numbered the way pierre numbers its rows.

```ts
interface FindLine
```

**Properties**

- `line` (`number`): 1-based line number on that side.
- `side` (`'old' | 'new'`): The diff side the line is on; `new` for a file's lines and a diff's context.
- `text` (`string`): The line's text, without its line ending.

Source: [ui/src/code/editor/find/find-model.ts:51](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L51)

### `FindOptions`

Interface.

How a query matches text.

```ts
interface FindOptions
```

**Properties**

- `caseSensitive` (`boolean`): Match letter case exactly; otherwise both sides are lowercased first.

Source: [ui/src/code/editor/find/find-model.ts:9](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L9)

### `LineMatch`

Interface.

One match on one rendered line. `side` tells a diff's old line from its new one.

```ts
interface LineMatch
```

**Properties**

- `end` (`number`): UTF-16 offset in the line just past the match.
- `line` (`number`): 1-based line number on that side, as pierre's `data-line`.
- `part` (`string`): Which diff a match is in (a file key and the diff's index in it); `''` for a lone file.
- `side` (`'old' | 'new'`): The diff side the line is on; always `new` in a lone file.
- `start` (`number`): UTF-16 offset in the line where the match starts.

Source: [ui/src/code/editor/find/find-model.ts:15](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/find/find-model.ts#L15)
