You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/docs/editor-api/events.mdx
+55-3
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,64 @@ editor.onCreate(() => {
26
26
The `onChange` callback is called when the editor content changes.
27
27
28
28
```typescript
29
-
editor.onChange(() => {
29
+
editor.onChange((editor, { getChanges }) => {
30
30
console.log("Editor updated");
31
+
const changes =getChanges();
32
+
console.log(changes);
31
33
});
32
34
```
33
35
36
+
You can see what specific changes occurred in the editor by calling `getChanges()` in the callback. This function returns an array of block changes which looks like:
37
+
38
+
```typescript
39
+
/**
40
+
* The changes that occurred in the editor.
41
+
*/
42
+
typeBlocksChanged=Array<
43
+
| {
44
+
// The affected block
45
+
block:Block;
46
+
// The source of the change
47
+
source:BlockChangeSource;
48
+
type:"insert"|"delete";
49
+
// Insert and delete changes don't have a previous block
50
+
prevBlock:undefined;
51
+
}
52
+
| {
53
+
// The affected block
54
+
block:Block;
55
+
// The source of the change
56
+
source:BlockChangeSource;
57
+
type:"update";
58
+
// The block before the update
59
+
prevBlock:Block;
60
+
}
61
+
)>;
62
+
63
+
/**
64
+
* This attributes the changes to a specific source.
65
+
*/
66
+
typeBlockChangeSource= {
67
+
/**
68
+
* The type of change source:
69
+
* - "local": Triggered by local user (default)
70
+
* - "paste": From paste operation
71
+
* - "drop": From drop operation
72
+
* - "undo"/"redo"/"undo-redo": From undo/redo operations
73
+
* - "yjs-remote": From remote user
74
+
*/
75
+
type:
76
+
|"local"
77
+
|"paste"
78
+
|"drop"
79
+
|"undo"
80
+
|"redo"
81
+
|"undo-redo"
82
+
|"yjs-remote";
83
+
};
84
+
```
85
+
86
+
34
87
## `onSelectionChange`
35
88
36
89
The `onSelectionChange` callback is called when the editor selection changes.
@@ -39,5 +92,4 @@ The `onSelectionChange` callback is called when the editor selection changes.
0 commit comments