Consider adding start, end, and blockKey to the props passed to DecoratorComponent
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What is the current behavior?
Currently, this is what we pass to DecoratorComponent
:
<DecoratorComponent
{...decoratorProps}
contentState={this.props.contentState}
decoratedText={decoratedText}
dir={dir}
key={decoratorOffsetKey}
entityKey={block.getEntityAt(leafSet.get('start'))}
offsetKey={decoratorOffsetKey}>
{leaves}
</DecoratorComponent>
What is the expected desired behavior?
I’ve had it occur a few times where I would like to know the start
and end
of the text being decorated.
One use case would be to decorate some text with a menu that can replace that given decorated text with a suggestion from the menu… I can extract the blockKey
from the offsetKey
, but I can’t easily figure out the start
or the end
from the given props.
My workaround is pretty janky - my decorator strategy uses a predefined list of ranges to find the text to decorate. Each decorated component I care about gets the same class, so then when I click replace with suggestion, I pass the replacement word as well as the node that’s being clicked to the callback. Then the editor finds the index of that node among all of the decorated components with that classname , and cross references that with the list of text ranges I used in the strategy to decorate in the first place.
start
, end
, and the blockKey
are readily available, but aren’t passed in.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:6
Top GitHub Comments
While the pull request is pending, i’ve created a small gist that shows how you might calculate
start
andend
range values for a decorator: https://gist.github.com/Nachasic/55ba65be46463c70336d700121ec4b6cI am having the same issue — trying to create a decorator with an entity bound to it, and I need to keep ranges in sync. Any progress on PR?