{"action":"created","comment":{"url":"https://api.github.com/repos/Yoast/yoast-components/pulls/comments/193340787","pull_request_review_id":126252488,"id":193340787,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5MzM0MDc4Nw==","diff_hunk":"@@ -0,0 +1,114 @@\n+import { EditorState, SelectionState, Modifier } from \"draft-js\";\n+\n+/**\n+ * Test if a character in a text is whitespace. Out of range index counts as whitespace.\n+ *\n+ * @param {string} text  The text to get the character from.\n+ * @param {int}    index The index of the character in the text.\n+ *\n+ * @returns {boolean} True if the character is out of bounds or whitespace.\n+ */\n+export const hasWhitespaceAt = ( text, index ) => {\n+\tconst char = text.charAt( index );\n+\n+\t// No character found equals whitespace.\n+\tif ( char.length === 0 ) {\n+\t\treturn true;\n+\t}\n+\n+\treturn /\\s/.test( char );\n+};\n+\n+/**\n+ * Gets the Draft.js caret offset.\n+ *\n+ * @param {SelectionState} selection The Draft.js selection state.\n+ *\n+ * @returns {int} The Draft.js caret offset.\n+ */\n+export const getCaretOffset = ( selection ) => {\n+\tconst isBackward = selection.getIsBackward();\n+\n+\t// If the selection is backwards the end offset is the caret.\n+\treturn isBackward ? selection.getEndOffset() : selection.getStartOffset();\n+};\n+\n+/**\n+ * Gets the block of the start of the current Draft.js selection.\n+ *\n+ * This is a tiny helper function to get the anchor key and then the block of that key.\n+ * Read more about the Draft.js selection state: https://draftjs.org/docs/api-reference-selection-state.html\n+ * Read more about the Draft.js content block: https://draftjs.org/docs/api-reference-content-block.html\n+ *\n+ * @param {ContentState}   content   The Draft.js content state.\n+ * @param {SelectionState} selection The Draft.js selection state.\n+ *\n+ * @returns {ContentBlock} The Draft.js ContentBlock.\n+ */\n+export const getAnchorBlock = ( content, selection ) => {\n+\tconst key = selection.getAnchorKey();\n+\treturn content.getBlockForKey( key );\n+};\n+\n+/**\n+ * Inserts text into the editor state.\n+ *\n+ * @param {EditorState} editorState The Draft.js editor state.\n+ * @param {string}      text        The text to insert.\n+ *\n+ * @returns {EditorState} The new editor state.\n+ */\n+export const insertText = ( editorState, text ) => {\n+\tconst content = editorState.getCurrentContent();\n+\tconst selection = editorState.getSelection();\n+\n+\t// If there is a selection instead of a caret do nothing.","path":"composites/Plugin/SnippetEditor/text.js","position":65,"original_position":65,"commit_id":"65b7d5fe94a0227ceb93bd4ddb3740558c39c198","original_commit_id":"65b7d5fe94a0227ceb93bd4ddb3740558c39c198","user":{"login":"IreneStr","id":17744553,"node_id":"MDQ6VXNlcjE3NzQ0NTUz","avatar_url":"https://avatars3.githubusercontent.com/u/17744553?v=4","gravatar_id":"","url":"https://api.github.com/users/IreneStr","html_url":"https://github.com/IreneStr","followers_url":"https://api.github.com/users/IreneStr/followers","following_url":"https://api.github.com/users/IreneStr/following{/other_user}","gists_url":"https://api.github.com/users/IreneStr/gists{/gist_id}","starred_url":"https://api.github.com/users/IreneStr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IreneStr/subscriptions","organizations_url":"https://api.github.com/users/IreneStr/orgs","repos_url":"https://api.github.com/users/IreneStr/repos","events_url":"https://api.github.com/users/IreneStr/events{/privacy}","received_events_url":"https://api.github.com/users/IreneStr/received_events","type":"User","site_admin":false},"body":"please add comma after 'caret' to improve readability","created_at":"2018-06-06T09:00:14Z","updated_at":"2018-06-06T09:11:09Z","html_url":"https://github.com/Yoast/yoast-components/pull/568#discussion_r193340787","pull_request_url":"https://api.github.com/repos/Yoast/yoast-components/pulls/568","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/comments/193340787"},"html":{"href":"https://github.com/Yoast/yoast-components/pull/568#discussion_r193340787"},"pull_request":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/568"}}},"pull_request":{"url":"https://api.github.com/repos/Yoast/yoast-components/pulls/568","id":191569908,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkxNTY5OTA4","html_url":"https://github.com/Yoast/yoast-components/pull/568","diff_url":"https://github.com/Yoast/yoast-components/pull/568.diff","patch_url":"https://github.com/Yoast/yoast-components/pull/568.patch","issue_url":"https://api.github.com/repos/Yoast/yoast-components/issues/568","number":568,"state":"open","locked":false,"title":"Add a button to insert a replacement variable in the snippet editor","user":{"login":"igorschoester","id":35524806,"node_id":"MDQ6VXNlcjM1NTI0ODA2","avatar_url":"https://avatars1.githubusercontent.com/u/35524806?v=4","gravatar_id":"","url":"https://api.github.com/users/igorschoester","html_url":"https://github.com/igorschoester","followers_url":"https://api.github.com/users/igorschoester/followers","following_url":"https://api.github.com/users/igorschoester/following{/other_user}","gists_url":"https://api.github.com/users/igorschoester/gists{/gist_id}","starred_url":"https://api.github.com/users/igorschoester/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igorschoester/subscriptions","organizations_url":"https://api.github.com/users/igorschoester/orgs","repos_url":"https://api.github.com/users/igorschoester/repos","events_url":"https://api.github.com/users/igorschoester/events{/privacy}","received_events_url":"https://api.github.com/users/igorschoester/received_events","type":"User","site_admin":false},"body":"## Summary\r\n\r\nThis PR can be summarized in the following changelog entry:\r\n\r\n* N/A\r\n\r\n## Relevant technical choices:\r\n\r\n* Adds the plus-circle path to the SvgIcon component.\r\n* Removes the current selected text.\r\n* Insert the trigger `%` and ensure the autocomplete gets shown by adding spaces around it as needed.\r\n* Move the caret if needed and focus the editor.\r\n* Copied the button style from the `EditSnippetButton`. And adapted to positioning.\r\n\r\n## Test instructions\r\n\r\nThis PR can be tested by following these steps:\r\n\r\n* Check thoroughly if you get the suggestions autocomplete every time you hit the button.\r\n* If there is any text selected it should be removed.\r\n* If the caret is surround by text it should make room around the % to make the autocomplete show.\r\n\r\nFixes #552 \r\n","created_at":"2018-05-30T20:23:01Z","updated_at":"2018-06-06T09:11:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"40fe8eeec347435102da446b115825bb89f88da8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/Yoast/yoast-components/milestones/17","html_url":"https://github.com/Yoast/yoast-components/milestone/17","labels_url":"https://api.github.com/repos/Yoast/yoast-components/milestones/17/labels","id":2743015,"node_id":"MDk6TWlsZXN0b25lMjc0MzAxNQ==","number":17,"title":"Snippet Preview","description":null,"creator":{"login":"herregroen","id":4620754,"node_id":"MDQ6VXNlcjQ2MjA3NTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4620754?v=4","gravatar_id":"","url":"https://api.github.com/users/herregroen","html_url":"https://github.com/herregroen","followers_url":"https://api.github.com/users/herregroen/followers","following_url":"https://api.github.com/users/herregroen/following{/other_user}","gists_url":"https://api.github.com/users/herregroen/gists{/gist_id}","starred_url":"https://api.github.com/users/herregroen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/herregroen/subscriptions","organizations_url":"https://api.github.com/users/herregroen/orgs","repos_url":"https://api.github.com/users/herregroen/repos","events_url":"https://api.github.com/users/herregroen/events{/privacy}","received_events_url":"https://api.github.com/users/herregroen/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":11,"state":"open","created_at":"2017-09-04T12:40:56Z","updated_at":"2018-06-06T07:15:41Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/Yoast/yoast-components/pulls/568/commits","review_comments_url":"https://api.github.com/repos/Yoast/yoast-components/pulls/568/comments","review_comment_url":"https://api.github.com/repos/Yoast/yoast-components/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yoast/yoast-components/issues/568/comments","statuses_url":"https://api.github.com/repos/Yoast/yoast-components/statuses/65b7d5fe94a0227ceb93bd4ddb3740558c39c198","head":{"label":"Yoast:stories/552-snippet-variables-inserter","ref":"stories/552-snippet-variables-inserter","sha":"65b7d5fe94a0227ceb93bd4ddb3740558c39c198","user":{"login":"Yoast","id":4690436,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2OTA0MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":64846946,"node_id":"MDEwOlJlcG9zaXRvcnk2NDg0Njk0Ng==","name":"yoast-components","full_name":"Yoast/yoast-components","owner":{"login":"Yoast","id":4690436,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2OTA0MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/yoast-components","description":"Accessible React components by Yoast","fork":false,"url":"https://api.github.com/repos/Yoast/yoast-components","forks_url":"https://api.github.com/repos/Yoast/yoast-components/forks","keys_url":"https://api.github.com/repos/Yoast/yoast-components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/yoast-components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/yoast-components/teams","hooks_url":"https://api.github.com/repos/Yoast/yoast-components/hooks","issue_events_url":"https://api.github.com/repos/Yoast/yoast-components/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/yoast-components/events","assignees_url":"https://api.github.com/repos/Yoast/yoast-components/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/yoast-components/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/yoast-components/tags","blobs_url":"https://api.github.com/repos/Yoast/yoast-components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/yoast-components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/yoast-components/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/yoast-components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/yoast-components/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/yoast-components/languages","stargazers_url":"https://api.github.com/repos/Yoast/yoast-components/stargazers","contributors_url":"https://api.github.com/repos/Yoast/yoast-components/contributors","subscribers_url":"https://api.github.com/repos/Yoast/yoast-components/subscribers","subscription_url":"https://api.github.com/repos/Yoast/yoast-components/subscription","commits_url":"https://api.github.com/repos/Yoast/yoast-components/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/yoast-components/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/yoast-components/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/yoast-components/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/yoast-components/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/yoast-components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/yoast-components/merges","archive_url":"https://api.github.com/repos/Yoast/yoast-components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/yoast-components/downloads","issues_url":"https://api.github.com/repos/Yoast/yoast-components/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/yoast-components/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/yoast-components/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/yoast-components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/yoast-components/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/yoast-components/releases{/id}","deployments_url":"https://api.github.com/repos/Yoast/yoast-components/deployments","created_at":"2016-08-03T13:10:33Z","updated_at":"2018-06-06T07:15:35Z","pushed_at":"2018-06-06T08:53:51Z","git_url":"git://github.com/Yoast/yoast-components.git","ssh_url":"git@github.com:Yoast/yoast-components.git","clone_url":"https://github.com/Yoast/yoast-components.git","svn_url":"https://github.com/Yoast/yoast-components","homepage":"","size":3402,"stargazers_count":17,"watchers_count":17,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":98,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":4,"open_issues":98,"watchers":17,"default_branch":"develop"}},"base":{"label":"Yoast:feature/react-snippet-editor","ref":"feature/react-snippet-editor","sha":"59a1fa543bc8c4d24bcc8d875c119658a469ff6f","user":{"login":"Yoast","id":4690436,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2OTA0MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":64846946,"node_id":"MDEwOlJlcG9zaXRvcnk2NDg0Njk0Ng==","name":"yoast-components","full_name":"Yoast/yoast-components","owner":{"login":"Yoast","id":4690436,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2OTA0MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/yoast-components","description":"Accessible React components by Yoast","fork":false,"url":"https://api.github.com/repos/Yoast/yoast-components","forks_url":"https://api.github.com/repos/Yoast/yoast-components/forks","keys_url":"https://api.github.com/repos/Yoast/yoast-components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/yoast-components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/yoast-components/teams","hooks_url":"https://api.github.com/repos/Yoast/yoast-components/hooks","issue_events_url":"https://api.github.com/repos/Yoast/yoast-components/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/yoast-components/events","assignees_url":"https://api.github.com/repos/Yoast/yoast-components/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/yoast-components/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/yoast-components/tags","blobs_url":"https://api.github.com/repos/Yoast/yoast-components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/yoast-components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/yoast-components/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/yoast-components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/yoast-components/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/yoast-components/languages","stargazers_url":"https://api.github.com/repos/Yoast/yoast-components/stargazers","contributors_url":"https://api.github.com/repos/Yoast/yoast-components/contributors","subscribers_url":"https://api.github.com/repos/Yoast/yoast-components/subscribers","subscription_url":"https://api.github.com/repos/Yoast/yoast-components/subscription","commits_url":"https://api.github.com/repos/Yoast/yoast-components/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/yoast-components/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/yoast-components/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/yoast-components/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/yoast-components/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/yoast-components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/yoast-components/merges","archive_url":"https://api.github.com/repos/Yoast/yoast-components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/yoast-components/downloads","issues_url":"https://api.github.com/repos/Yoast/yoast-components/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/yoast-components/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/yoast-components/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/yoast-components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/yoast-components/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/yoast-components/releases{/id}","deployments_url":"https://api.github.com/repos/Yoast/yoast-components/deployments","created_at":"2016-08-03T13:10:33Z","updated_at":"2018-06-06T07:15:35Z","pushed_at":"2018-06-06T08:53:51Z","git_url":"git://github.com/Yoast/yoast-components.git","ssh_url":"git@github.com:Yoast/yoast-components.git","clone_url":"https://github.com/Yoast/yoast-components.git","svn_url":"https://github.com/Yoast/yoast-components","homepage":"","size":3402,"stargazers_count":17,"watchers_count":17,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":98,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":4,"open_issues":98,"watchers":17,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/568"},"html":{"href":"https://github.com/Yoast/yoast-components/pull/568"},"issue":{"href":"https://api.github.com/repos/Yoast/yoast-components/issues/568"},"comments":{"href":"https://api.github.com/repos/Yoast/yoast-components/issues/568/comments"},"review_comments":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/568/comments"},"review_comment":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yoast/yoast-components/pulls/568/commits"},"statuses":{"href":"https://api.github.com/repos/Yoast/yoast-components/statuses/65b7d5fe94a0227ceb93bd4ddb3740558c39c198"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"IreneStr"}}