# History

Class · extends `Events` · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/history.ts#L7

The history API responsible for undo / redo.

## Constructors

### constructor

```ts
new History()
```

Creates new instance of the API

## Accessors

### canRedo

```ts
get canRedo(): boolean
set canRedo(value: boolean)
```

Gets whether there are actions to redo.

### canUndo

```ts
get canUndo(): boolean
set canUndo(value: boolean)
```

Gets whether there are actions to undo.

### currentAction

```ts
get currentAction(): HistoryAction
```

Gets the current action

### lastAction

```ts
get lastAction(): HistoryAction
```

Gets the last action

## Methods

### add

```ts
add(action: HistoryAction): void
```

Adds history action

**Parameters**

- `action` (`HistoryAction`): The action

**Example**

```javascript
const prevSelection = editor.selection.items;
editor.history.add({
    name: 'clear selection',
    redo: () => { editor.selection.clear({ history: false }); },
    undo: () => { editor.selection.set(prevSelection, { history: false }); },
});
```

### addAndExecute

```ts
addAndExecute(action: HistoryAction): void
```

Adds history action and execute redo

**Parameters**

- `action` (`HistoryAction`): The action

**Example**

```javascript
const prevSelection = editor.selection.items;
editor.history.addAndExecute({
    name: 'clear selection',
    redo: () => { editor.selection.clear({ history: false }); },
    undo: () => { editor.selection.set(prevSelection, { history: false }); },
});
```

### clear

```ts
clear(): void
```

Clear history

**Example**

```javascript
editor.history.clear();
```

### redo

```ts
redo(): void
```

Redo last action

**Example**

```javascript
editor.history.redo();
```

### undo

```ts
undo(): void
```

Undo last action

**Example**

```javascript
editor.history.undo();
```
