1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-23 15:32:59 +02:00

Merge branch 'master' of github.com:ianstormtaylor/slate

This commit is contained in:
Ian Storm Taylor
2018-04-27 16:05:40 -07:00
2 changed files with 27 additions and 0 deletions

View File

@@ -78,6 +78,19 @@ validateNode(node) {
} }
``` ```
## Full Value Change
### `setValue`
`setValue(properties: Object, [options: Object]) => Change` <br/>
`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 ## 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. 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.

View File

@@ -707,6 +707,20 @@ Changes.insertFragmentAtRange = (change, range, fragment, options = {}) => {
return 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 // 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. // nodes after the fragment's first block at the index.
if (firstBlock != lastBlock) { if (firstBlock != lastBlock) {