refactor(editor): move history from doc to store (#12131)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Undo/redo history management is now centralized in the workspace, providing more consistent and robust undo/redo behavior.
  - History update events are emitted at the workspace level, enabling better tracking of changes.

- **Bug Fixes**
  - Improved reliability of undo/redo actions by shifting history management from documents to the workspace.

- **Documentation**
  - Updated and clarified documentation for history-related APIs, including improved examples and clearer descriptions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-05-05 09:24:09 +00:00
parent 61af6fd24e
commit d859c4252b
12 changed files with 145 additions and 337 deletions

View File

@@ -721,36 +721,6 @@ Check if the store can undo
***
### captureSync
#### Get Signature
> **get** **captureSync**(): () => `void`
Force the following history to be captured into a new stack.
##### Example
```ts
op1();
op2();
store.captureSync();
op3();
store.undo(); // undo op3
store.undo(); // undo op1, op2
```
##### Returns
> (): `void`
###### Returns
`void`
***
### history
#### Get Signature
@@ -765,51 +735,75 @@ Get the Y.UndoManager instance for current store.
***
### redo
### captureSync()
#### Get Signature
> **captureSync**(): `void`
> **get** **redo**(): () => `void`
Force the following history to be captured into a new stack.
#### Returns
`void`
#### Example
```ts
op1();
op2();
store.captureSync();
op3();
store.undo(); // undo op3
store.undo(); // undo op1, op2
```
***
### redo()
> **redo**(): `void`
Redo the last undone transaction.
##### Returns
> (): `void`
###### Returns
#### Returns
`void`
***
### resetHistory
### resetHistory()
#### Get Signature
> **get** **resetHistory**(): () => `void`
> **resetHistory**(): `void`
Reset the history of the store.
##### Returns
> (): `void`
###### Returns
#### Returns
`void`
***
### transact
### transact()
#### Get Signature
> **get** **transact**(): (`fn`, `shouldTransact?`) => `void`
> **transact**(`fn`, `shouldTransact`): `void`
Execute a transaction.
##### Example
#### Parameters
##### fn
() => `void`
##### shouldTransact
`boolean` = `...`
#### Returns
`void`
#### Example
```ts
store.transact(() => {
@@ -818,53 +812,37 @@ store.transact(() => {
});
```
##### Returns
> (`fn`, `shouldTransact?`): `void`
###### Parameters
###### fn
() => `void`
###### shouldTransact?
`boolean`
###### Returns
`void`
***
### undo
### undo()
#### Get Signature
> **get** **undo**(): () => `void`
> **undo**(): `void`
Undo the last transaction.
##### Returns
> (): `void`
###### Returns
#### Returns
`void`
***
### withoutTransact
### withoutTransact()
#### Get Signature
> **get** **withoutTransact**(): (`fn`) => `void`
> **withoutTransact**(`fn`): `void`
Execute a transaction without capturing the history.
##### Example
#### Parameters
##### fn
() => `void`
#### Returns
`void`
#### Example
```ts
store.withoutTransact(() => {
@@ -873,20 +851,6 @@ store.withoutTransact(() => {
});
```
##### Returns
> (`fn`): `void`
###### Parameters
###### fn
() => `void`
###### Returns
`void`
## Store Lifecycle
### disposableGroup