Modifier
The Modifier
module is a static set of utility functions that encapsulate common
edit operations on ContentState
objects. It is highly recommended that you use
these methods for edit operations.
These methods also take care of removing or modifying entity ranges appropriately, given the mutability types of any affected entities.
In each case, these methods accept ContentState
objects with relevant
parameters and return ContentState
objects. The returned ContentState
will be the same as the input object if no edit was actually performed.
Overview
Methods
- replaceText(...): ContentState
- insertText(...): ContentState
- moveText(...): ContentState
- replaceWithFragment(...): ContentState
- removeRange(...): ContentState
- splitBlock(...): ContentState
- applyInlineStyle(...): ContentState
- removeInlineStyle(...): ContentState
- setBlockType(...): ContentState
- setBlockData(...): ContentState
- mergeBlockData(...): ContentState
- applyEntity(...): ContentState
Static Methods
replaceText()
Replaces the specified range of this ContentState
with the supplied string,
with the inline style and entity key applied to the entire inserted string.
Example: On Facebook, when replacing @abraham lincoln
with a mention of
Abraham Lincoln, the entire old range is the target to replace and the mention
entity should be applied to the inserted string.
insertText()
Identical to replaceText
, but enforces that the target range is collapsed
so that no characters are replaced. This is only for convenience, since text
edits are so often insertions rather than replacements.
moveText()
Moves the "removal" range to the "target" range, replacing the target text.
replaceWithFragment()
A "fragment" is a section of a block map, effectively only an
OrderedMap<string, ContentBlock>
much the same as the full block map of a
ContentState
object.
This method will replace the "target" range with the fragment.
Example: When pasting content, we convert the paste into a fragment to be inserted into the editor, then use this method to add it.
removeRange()
Remove an entire range of text from the editor. The removal direction is important for proper entity deletion behavior.
splitBlock()
Split the selected block into two blocks. This should only be used if the selection is collapsed.
applyInlineStyle()
Apply the specified inline style to the entire selected range.
removeInlineStyle()
Remove the specified inline style from the entire selected range.
setBlockType()
Set the block type for all selected blocks.
setBlockData()
Set the block data for all selected blocks.
mergeBlockData()
Update block data for all selected blocks.
applyEntity()
Apply an entity to the entire selected range, or remove all entities from the range if entityKey
is null
.