Skip to content

Type Editor


Type Editor / @type-editor/search / SearchQuery / SearchQuery

Class: SearchQuery

Defined in: SearchQuery.ts:24

Constructors

Constructor

ts
new SearchQuery(config): SearchQuery;

Defined in: SearchQuery.ts:72

Creates a new search query object.

Parameters

ParameterTypeDescription
configSearchQueryConfigConfiguration options for the search query

Returns

SearchQuery

Accessors

caseSensitive

Get Signature

ts
get caseSensitive(): boolean;

Defined in: SearchQuery.ts:98

Gets whether the search is case-sensitive.

Returns

boolean


Get Signature

ts
get search(): string;

Defined in: SearchQuery.ts:91

Gets the search string or regular expression pattern.

Returns

string


valid

Get Signature

ts
get valid(): boolean;

Defined in: SearchQuery.ts:105

Gets whether this query is valid (non-empty and syntactically correct if regex).

Returns

boolean

Methods

eq()

ts
eq(other): boolean;

Defined in: SearchQuery.ts:116

Compares this query to another query for equality. Two queries are equal if all their configuration options match.

Parameters

ParameterTypeDescription
otherSearchQueryThe query to compare with

Returns

boolean

true if the queries are equal, false otherwise


findNext()

ts
findNext(
   state,
   from?,
   to?): SearchResult;

Defined in: SearchQuery.ts:135

Finds the next occurrence of this query in the given range. The search continues forward from the from position until a match is found or the end of the range is reached.

Parameters

ParameterTypeDefault valueDescription
statePmEditorStateundefinedThe editor state to search in
fromnumber0The position to start searching from (default: 0)
tonumberstate.doc.content.sizeThe position to search up to (default: document size)

Returns

SearchResult

The search result if found, or null if no match exists


findPrev()

ts
findPrev(
   state,
   from?,
   to?): SearchResult;

Defined in: SearchQuery.ts:168

Finds the previous occurrence of this query in the given range. The search continues backward from the from position until a match is found or the start of the range is reached.

Note: When searching backward, from should be greater than to.

Parameters

ParameterTypeDefault valueDescription
statePmEditorStateundefinedThe editor state to search in
fromnumberstate.doc.content.sizeThe position to start searching from (default: document size)
tonumber0The position to search back to (default: 0)

Returns

SearchResult

The search result if found, or null if no match exists


getReplacements()

ts
getReplacements(state, result): ReplacementRange[];

Defined in: SearchQuery.ts:233

Generates the ranges that should be replaced for a search result. This can return multiple ranges when this.replace contains capture group placeholders like $1, $2, or $&, in which case the preserved content is skipped by the replacements.

Ranges are sorted by position, and from/to positions all refer to positions in state.doc. When applying these, you should either apply them from back to front, or map these positions through your transaction's current mapping.

Parameters

ParameterTypeDescription
statePmEditorStateThe editor state containing the document
resultSearchResultThe search result to generate replacements for

Returns

ReplacementRange[]

An array of replacement ranges with their insertion slices


unquote()

ts
unquote(text): string;

Defined in: SearchQuery.ts:197

Processes escape sequences in the given text. If literal mode is enabled, returns text as-is. Otherwise, replaces escape sequences: \n → newline, \r → return, \t → tab, \\ → backslash.

Parameters

ParameterTypeDescription
textstringThe text to process

Returns

string

The processed text with escape sequences replaced (unless in literal mode)