Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 3a3d34b

Browse files
Matthew Mansfacebook-github-bot
Matthew Mans
authored andcommitted
expose start/end positions of a decorated component within a contentBlock
Summary: In some cases, it's valuable to expose the current position of a decorated component within its content block for styling purposes. (Example: Apply certain styling to a decorated component if a certain entitiy is directly next to that component). Reviewed By: flarnie Differential Revision: D6712533 fbshipit-source-id: ea25ae65fafba5283a344a091ac2346fcd4e9bb3
1 parent 900ef76 commit 3a3d34b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/component/contents/DraftEditorBlock.react.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ class DraftEditorBlock extends React.Component<Props> {
186186

187187
const decoratorProps = decorator.getPropsForKey(decoratorKey);
188188
const decoratorOffsetKey = DraftOffsetKey.encode(blockKey, ii, 0);
189-
const decoratedText = text.slice(
190-
leavesForLeafSet.first().get('start'),
191-
leavesForLeafSet.last().get('end'),
192-
);
189+
const start = leavesForLeafSet.first().get('start');
190+
const end = leavesForLeafSet.last().get('end');
191+
const decoratedText = text.slice(start, end);
193192

194193
// Resetting dir to the same value on a child node makes Chrome/Firefox
195194
// confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
@@ -205,6 +204,9 @@ class DraftEditorBlock extends React.Component<Props> {
205204
decoratedText={decoratedText}
206205
dir={dir}
207206
key={decoratorOffsetKey}
207+
start={start}
208+
end={end}
209+
blockKey={blockKey}
208210
entityKey={block.getEntityAt(leafSet.get('start'))}
209211
offsetKey={decoratorOffsetKey}>
210212
{leaves}

0 commit comments

Comments
 (0)