1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 21:21:21 +02:00

Clarifies when to use Editor.insertNode vs. Transforms.insertNodes (#4731)

This commit is contained in:
Doug Reeder
2021-12-18 09:05:10 -05:00
committed by GitHub
parent 65708358bb
commit 228cee56a1
2 changed files with 16 additions and 6 deletions

View File

@@ -44,10 +44,20 @@ Options: `{at?: Location, hanging?: boolean, voids?: boolean}`
#### `Transforms.insertNodes(editor: Editor, nodes: Node | Node[], options?)`
Insert `nodes` at the specified location in the document. If no location is specified, insert at the current selection. If there is no selection, insert at the end of the document.
Atomically inserts `nodes` at the specified location in the document. If no location is specified, inserts at the current selection. If there is no selection, inserts at the end of the document.
Options supported: `NodeOptions & {hanging?: boolean, select?: boolean}`.
For example, to insert at the very end, without replacing the current selection and regardless of block nesting, use
```javascript
Transforms.insertNodes(
editor,
{ type: targetType, children: [{ text: '' }] },
{ at: [editor.children.length] }
)
```
#### `Transforms.removeNodes(editor: Editor, options?)`
Remove nodes at the specified location in the document. If no location is specified, remove the nodes in the selection.