{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/draft-js/issues/68","repository_url":"https://api.github.com/repos/facebook/draft-js","labels_url":"https://api.github.com/repos/facebook/draft-js/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/facebook/draft-js/issues/68/comments","events_url":"https://api.github.com/repos/facebook/draft-js/issues/68/events","html_url":"https://github.com/facebook/draft-js/issues/68","id":136175960,"number":68,"title":"content.findEntityRanges() fails to find Entities after calling Modifier.applyEntity().","user":{"login":"ben-davis","id":2607068,"avatar_url":"https://avatars.githubusercontent.com/u/2607068?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-davis","html_url":"https://github.com/ben-davis","followers_url":"https://api.github.com/users/ben-davis/followers","following_url":"https://api.github.com/users/ben-davis/following{/other_user}","gists_url":"https://api.github.com/users/ben-davis/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-davis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-davis/subscriptions","organizations_url":"https://api.github.com/users/ben-davis/orgs","repos_url":"https://api.github.com/users/ben-davis/repos","events_url":"https://api.github.com/users/ben-davis/events{/privacy}","received_events_url":"https://api.github.com/users/ben-davis/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/draft-js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-24T20:20:00Z","updated_at":"2016-03-03T03:40:08Z","closed_at":"2016-03-03T03:40:08Z","body":"I'm using Draft to highlight hashtags in a readonly block of text (I understand Draft might not be the right tool for the job considering I don't require selection).\r\n\r\nFrom what I understand, the correct approach should be:\r\n- map over each `contentBlock`\r\n- for each `contentBlock` find `(start, end)` ranges for each hashtag\r\n- for each hashtag, create an `Entity` and a `SelectionState` for the tag\r\n- apply that `Entity` using `Modifier.applyEntity` for the given `SelectionState`.\r\n\r\nHere's what that looks like\r\n\r\n```javascript\r\nconst contentState = ContentState.createFromText(content);\r\ncontentState.getBlockMap().map(contentBlock => {\r\n  this._findWithRegex(HASHTAG_REGEX, contentBlock, (start, end) => {\r\n    let selectionState = SelectionState.createEmpty(contentBlock.getKey());\r\n    selectionState = selectionState.merge({\r\n      anchorOffset: start,\r\n      focusKey: contentBlock.getKey(),\r\n      focusOffset: end,\r\n    });\r\n\r\n    const tag = contentBlock.getText().slice(start, end);\r\n    const key = Entity.create('HASHTAG', 'MUTABLE', {tag: tag});\r\n\r\n    Modifier.applyEntity(contentState, selectionState, key);\r\n  });\r\n});\r\n```\r\nwhere `this._findWithRegex` is the same function from the `tweet` example.\r\n\r\nAfter doing this, I expect to be able to apply a decorator strategy using the following:\r\n```javascript\r\n_findHashtagEntitiesStrategy(contentBlock, callback) {\r\n  contentBlock.findEntityRanges(\r\n    (character) => {\r\n      const entityKey = character.getEntity();\r\n      return (\r\n        entityKey !== null &&\r\n        Entity.get(entityKey).getType() === 'HASHTAG'\r\n      );\r\n    },\r\n    callback\r\n  );\r\n}\r\n```\r\nHowever it seems that `contentBlock.findEntityRanges` fails to find any `Entity`s for the any of the `ContentBlock`s."},"comment":{"url":"https://api.github.com/repos/facebook/draft-js/issues/comments/191565761","html_url":"https://github.com/facebook/draft-js/issues/68#issuecomment-191565761","issue_url":"https://api.github.com/repos/facebook/draft-js/issues/68","id":191565761,"user":{"login":"hellendag","id":2823852,"avatar_url":"https://avatars.githubusercontent.com/u/2823852?v=3","gravatar_id":"","url":"https://api.github.com/users/hellendag","html_url":"https://github.com/hellendag","followers_url":"https://api.github.com/users/hellendag/followers","following_url":"https://api.github.com/users/hellendag/following{/other_user}","gists_url":"https://api.github.com/users/hellendag/gists{/gist_id}","starred_url":"https://api.github.com/users/hellendag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hellendag/subscriptions","organizations_url":"https://api.github.com/users/hellendag/orgs","repos_url":"https://api.github.com/users/hellendag/repos","events_url":"https://api.github.com/users/hellendag/events{/privacy}","received_events_url":"https://api.github.com/users/hellendag/received_events","type":"User","site_admin":false},"created_at":"2016-03-03T03:40:08Z","updated_at":"2016-03-03T03:40:08Z","body":"Resolved by #144."}}