# EditorSession

Source: /tuil/docs/reference/packages/editor/api/editor-session
Locale: en

interface exported by @mwillbanks/tuil-editor.



{/* Generated by tooling/docs/generate-reference.ts. */}

## interface [#interface]

Public interface exported by `@mwillbanks/tuil-editor`.

```ts
export interface EditorSession {
  snapshot(): EditorSnapshot;
  dispatch(transaction: EditorTransaction): EditorSnapshot;
  execute(
    command: string | EditorCommand,
    argument?: unknown,
  ): boolean | Promise<boolean>;
  undo(): boolean;
  redo(): boolean;
  search(query: string | RegExp): readonly EditorRange[];
  replace(query: string | RegExp, replacement: string, all?: boolean): number;
  copy(): string | Promise<string>;
  cut(): string | Promise<string>;
  paste(value?: string): boolean | Promise<boolean>;
  serialize(format?: "text" | "json" | "markdown"): string;
  subscribe(observer: (snapshot: EditorSnapshot) => void): () => void;
  key?(input: string): boolean;
  dispose(): void;
}
```

## Members [#members]

| Member      | Type                                                                                    | Required | Description                                                                                                                     | Related types                                                                                                                                          |
| ----------- | --------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `snapshot`  | `() => EditorSnapshot`                                                                  | Yes      | The `snapshot` member uses the `() => EditorSnapshot` contract.                                                                 | [`EditorSnapshot`](/tuil/docs/reference/packages/editor/api/editor-snapshot)                                                                                |
| `dispatch`  | `(transaction: EditorTransaction) => EditorSnapshot`                                    | Yes      | The `dispatch` member uses the `(transaction: EditorTransaction) => EditorSnapshot` contract.                                   | [`EditorSnapshot`](/tuil/docs/reference/packages/editor/api/editor-snapshot), [`EditorTransaction`](/tuil/docs/reference/packages/editor/api/editor-transaction) |
| `execute`   | `(command: string \| EditorCommand, argument?: unknown) => boolean \| Promise<boolean>` | Yes      | The `execute` member uses the `(command: string \| EditorCommand, argument?: unknown) => boolean \| Promise<boolean>` contract. | [`EditorCommand`](/tuil/docs/reference/packages/editor/api/editor-command)                                                                                  |
| `undo`      | `() => boolean`                                                                         | Yes      | The `undo` member uses the `() => boolean` contract.                                                                            | —                                                                                                                                                      |
| `redo`      | `() => boolean`                                                                         | Yes      | The `redo` member uses the `() => boolean` contract.                                                                            | —                                                                                                                                                      |
| `search`    | `(query: string \| RegExp) => readonly EditorRange[]`                                   | Yes      | The `search` member uses the `(query: string \| RegExp) => readonly EditorRange[]` contract.                                    | [`EditorRange`](/tuil/docs/reference/packages/editor/api/editor-range)                                                                                      |
| `replace`   | `(query: string \| RegExp, replacement: string, all?: boolean) => number`               | Yes      | The `replace` member uses the `(query: string \| RegExp, replacement: string, all?: boolean) => number` contract.               | —                                                                                                                                                      |
| `copy`      | `() => string \| Promise<string>`                                                       | Yes      | The `copy` member uses the `() => string \| Promise<string>` contract.                                                          | —                                                                                                                                                      |
| `cut`       | `() => string \| Promise<string>`                                                       | Yes      | The `cut` member uses the `() => string \| Promise<string>` contract.                                                           | —                                                                                                                                                      |
| `paste`     | `(value?: string) => boolean \| Promise<boolean>`                                       | Yes      | The `paste` member uses the `(value?: string) => boolean \| Promise<boolean>` contract.                                         | —                                                                                                                                                      |
| `serialize` | `(format?: "text" \| "json" \| "markdown") => string`                                   | Yes      | The `serialize` member uses the `(format?: "text" \| "json" \| "markdown") => string` contract.                                 | —                                                                                                                                                      |
| `subscribe` | `(observer: (snapshot: EditorSnapshot) => void) => () => void`                          | Yes      | The `subscribe` member uses the `(observer: (snapshot: EditorSnapshot) => void) => () => void` contract.                        | [`EditorSnapshot`](/tuil/docs/reference/packages/editor/api/editor-snapshot)                                                                                |
| `key`       | `((input: string) => boolean) \| undefined`                                             | No       | The `key` member uses the `((input: string) => boolean) \| undefined` contract.                                                 | —                                                                                                                                                      |
| `dispose`   | `() => void`                                                                            | Yes      | The `dispose` member uses the `() => void` contract.                                                                            | —                                                                                                                                                      |

## Parameters [#parameters]

This declaration has no public members.

## Returns [#returns]

This declaration does not return a value.

## Throws [#throws]

No thrown errors are documented for this declaration.

## Related types [#related-types]

* [`EditorCommand`](/tuil/docs/reference/packages/editor/api/editor-command)
* [`EditorRange`](/tuil/docs/reference/packages/editor/api/editor-range)
* [`EditorSnapshot`](/tuil/docs/reference/packages/editor/api/editor-snapshot)
* [`EditorTransaction`](/tuil/docs/reference/packages/editor/api/editor-transaction)

## Source [#source]

[View the secondary source reference](https://github.com/mwillbanks/tuil/blob/main/packages/editor/src/index.ts)

## Package [#package]

[@mwillbanks/tuil-editor](/tuil/docs/reference/packages/editor)
