Skip to content

code/editor/find/find-model

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/find/find-model.ts

Functions#

diffLinesFunction#

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

TypeScript
function diffLines(diff: FileDiffMetadata): FindLine[]
Parameters
NameTypeDescription
diffFileDiffMetadata

The parsed diff of one file.

ui/src/code/editor/find/find-model.ts:74

fileLinesFunction#

A file's lines, numbered from 1.

TypeScript
function fileLines(contents: string): FindLine[]
Parameters
NameTypeDescription
contentsstring

The whole file; \r\n endings are stripped.

ui/src/code/editor/find/find-model.ts:65

findAllFunction#

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

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

The lines to search, grouped by the diff (or file) they belong to.

querystring

The literal string to look for.

optsFindOptions

Case sensitivity.

{ capped: boolean; matches: LineMatch[] }

ui/src/code/editor/find/find-model.ts:107

matchesInFunction#

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

TypeScript
function matchesIn(
  text: string,
  query: string,
  opts: FindOptions,
): { end: number; start: number }[]
Parameters
NameTypeDescription
textstring

The text to search, such as one line.

querystring

The literal string to look for (not a pattern).

optsFindOptions

Case sensitivity.

{ end: number; start: number }[]

ui/src/code/editor/find/find-model.ts:39

Constants#

MAX_FIND_MATCHESConstant#

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

TypeScript
const MAX_FIND_MATCHES = 5000

ui/src/code/editor/find/find-model.ts:29

Interfaces#

FindLineInterface#

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

TypeScript
interface FindLine
FindLine properties
NameTypeDescription
linenumber

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.

textstring

The line's text, without its line ending.

ui/src/code/editor/find/find-model.ts:51

FindOptionsInterface#

How a query matches text.

TypeScript
interface FindOptions
FindOptions properties
NameTypeDescription
caseSensitiveboolean

Match letter case exactly; otherwise both sides are lowercased first.

ui/src/code/editor/find/find-model.ts:9

LineMatchInterface#

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

TypeScript
interface LineMatch
LineMatch properties
NameTypeDescription
endnumber

UTF-16 offset in the line just past the match.

linenumber

1-based line number on that side, as pierre's data-line.

partstring

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.

startnumber

UTF-16 offset in the line where the match starts.

ui/src/code/editor/find/find-model.ts:15