# Search

A class designed to handle all sorts of text searches within a `Document`.

### Constructors

- - new Search()

Creates a new `Search` object. The following search options are avaliable:

Creates a new `Search` object. The following search options are avaliable:

- `needle`: The string or regular expression you're looking for
- `backwards`: Whether to search backwards from where cursor currently is. Defaults to `false`.
- `wrap`: Whether to wrap the search back to the beginning when it hits the end. Defaults to `false`.
- `caseSensitive`: Whether the search ought to be case-sensitive. Defaults to `false`.
- `wholeWord`: Whether the search matches only on whole words. Defaults to `false`.
- `range`: The `Range` to search within. Set this to `null` for the whole document
- `regExp`: Whether the search is a regular expression or not. Defaults to `false`.
- `start`: The starting `Range` or cursor position to begin the search
- `skipCurrent`: Whether or not to include the current line in the search. Default to `false`.

### Methods

- - Search.find(EditSession session)
  - - Range

Searches for `options.needle`. If found, this method returns the `Range` where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.

Searches for `options.needle`. If found, this method returns the `Range` where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.

#### Arguments

session | EditSession | Required. The session to search with

- - Search.findAll(EditSession session)
  - - Range

Searches for all occurances `options.needle`. If found, this method returns an array of `Range`s where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.

Searches for all occurances `options.needle`. If found, this method returns an array of `Range`s where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session.

#### Arguments

session | EditSession | Required. The session to search with

- - Search.getOptions()
  - - Object

Returns an object containing all the search options.

Returns an object containing all the search options.

- - Search.replace(String input, String replacement)
  - - String

Searches for `options.needle` in `input`, and, if found, replaces it with `replacement`.

Searches for `options.needle` in `input`, and, if found, replaces it with `replacement`.

#### Arguments

input | String | Required. The text to search in
replacement | String | Required. The replacing text (String): If `options.regExp` is `true`, this function returns `input` with the replacement already made. Otherwise, this function just returns `replacement`. If `options.needle` was not found, this function returns `null`.

- - Search.set(Object options)
  - - Search

- Chainable

Sets the search options via the `options` parameter.

Sets the search options via the `options` parameter.

#### Arguments

options | Object | Required. An object containing all the new search properties

- - Search.setOptions()
  - Undocumented