1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-20 13:22:04 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -276,19 +276,19 @@ Insert a block break at the current selection.
#### `Editor.insertFragment(editor: Editor, fragment: Node[]) => void`
Insert a fragment at the current selection.
Inserts a fragment _at the current selection_.
If the selection is currently expanded, it will be deleted first.
If the selection is currently expanded, it will be deleted first. To atomically insert nodes (including at the very beginning or end), use [Transforms.insertNodes](../transforms.md#transformsinsertnodeseditor-editor-nodes-node--node-options).
#### `Editor.insertNode(editor: Editor, node: Node) => void`
Insert a node at the current selection.
Inserts a node _at the current selection_.
If the selection is currently expanded, it will be deleted first.
If the selection is currently expanded, it will be deleted first. To atomically insert a node (including at the very beginning or end), use [Transforms.insertNodes](../transforms.md#transformsinsertnodeseditor-editor-nodes-node--node-options).
#### `Editor.insertText(editor: Editor, text: string) => void`
Insert text at the current selection.
Inserts text _at the current selection_.
If the selection is currently expanded, it will be deleted first.

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.