diff --git a/docs/reference/slate/change.md b/docs/reference/slate/change.md index d02347f2f..29a7abf3d 100644 --- a/docs/reference/slate/change.md +++ b/docs/reference/slate/change.md @@ -78,6 +78,19 @@ validateNode(node) { } ``` +## Full Value Change + +### `setValue` + +`setValue(properties: Object, [options: Object]) => Change`
+`setValue(value: Value, [options: Object]) => Change` (see warning below) + +Set the entire `value` using either a `properties` object or a `Value` object. Can be used to set `value.data` and other properties that cannot otherwise be easily set using the available methods. + +Warning: Calling `setValue` with a `Value` object has unpredictable behavior including the loss of the edit history. Only use with a `Value` object if you know what you are doing. For most use cases, we recommend passing `properties` as an `Object` (e.g. `change.setValue({data: myNewDataObject})`. + +Hint: Wrapping the call to `setValue` as follows can be helpful if you want to update a value, like in the value's `data` but do not want to have another save point in the undo history: `change.setOperationFlag({save: false}).change({data: myNewDataObject}).setOperationFlag({save: true}). + ## Current Value Changes These changes act on the `document` based on the current `selection`. They are equivalent to calling the [Document Changes](#document-changes) with the current selection as the `range` argument, but they are there for convenience, since you often want to act with the current selection, as a user would. diff --git a/packages/slate/src/changes/at-range.js b/packages/slate/src/changes/at-range.js index 5d429b90d..cc008d829 100644 --- a/packages/slate/src/changes/at-range.js +++ b/packages/slate/src/changes/at-range.js @@ -707,6 +707,20 @@ Changes.insertFragmentAtRange = (change, range, fragment, options = {}) => { return } + // If the fragment starts or ends with single nested block, (e.g., table), + // do not merge this fragment with existing blocks. + if ( + firstBlock != lastBlock && + Block.isBlock(fragment.nodes.first()) && + Block.isBlock(fragment.nodes.last()) && + (firstBlock != fragment.nodes.first() || lastBlock != fragment.nodes.last()) + ) { + fragment.nodes.reverse().forEach((node) => { + change.insertBlockAtRange(range, node, options) + }) + return + } + // If the first and last block aren't the same, we need to insert all of the // nodes after the fragment's first block at the index. if (firstBlock != lastBlock) {