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
will be the same as the input object if no edit was actually performed.
- replaceText(...): ContentState
- insertText(...): ContentState
- moveText(...): ContentState
- replaceWithFragment(...): ContentState
- removeRange(...): ContentState
- splitBlock(...): ContentState
- applyInlineStyle(...): ContentState
- removeInlineStyle(...): ContentState
- setBlockType(...): ContentState
- setBlockData(...): ContentState
- mergeBlockData(...): ContentState
- applyEntity(...): ContentState
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.
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.
Moves the "removal" range to the "target" range, replacing the target text.
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
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.
Remove an entire range of text from the editor. The removal direction is important for proper entity deletion behavior.
Split the selected block into two blocks. This should only be used if the selection is collapsed.
Apply the specified inline style to the entire selected range.
Remove the specified inline style from the entire selected range.
Set the block type for all selected blocks.
Set the block data for all selected blocks.
Update block data for all selected blocks.
Apply an entity to the entire selected range, or remove all entities from the range if