{"action":"created","comment":{"url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/comments/175081418","pull_request_review_id":104555255,"id":175081418,"diff_hunk":"@@ -0,0 +1,164 @@\n+function expandRightSingleCursor(\n+    expandBy,\n+    boundaryBlockKey,\n+    boundaryOffset,\n+    currentBlockKey,\n+    currentOffset,\n+    limitedToSingleBlock,\n+    contentState\n+) {\n+    const boundaryViolated = currentBlockKey === boundaryBlockKey && currentOffset + expandBy >= boundaryOffset;\n+\n+    if (boundaryViolated) {\n+        return {\n+            blockKey: boundaryBlockKey,\n+            offset: boundaryOffset\n+        };\n+    }\n+\n+    // check if resizing can be resolved in the current block\n+\n+    const currentBlock = contentState.getBlockForKey(currentBlockKey);\n+\n+    if (currentOffset + expandBy <= currentBlock.getLength()) {\n+        return {\n+            blockKey: currentBlockKey,\n+            offset: currentOffset + expandBy\n+        };\n+    }\n+\n+    // jump to the start of the block after\n+\n+    const blockAfter = contentState.getBlockAfter(currentBlockKey);\n+\n+    if (blockAfter === null || blockAfter === undefined || limitedToSingleBlock) {\n+        return {\n+            blockKey: currentBlockKey,\n+            offset: currentBlock.getLength()\n+        };\n+    }\n+\n+    const nextStretchRight = (currentOffset + expandBy) - currentBlock.getLength();\n+    const nextOffset = 0;\n+    const nextBlockKey = blockAfter.getKey();\n+\n+    return expandRightSingleCursor(\n+        nextStretchRight,\n+        boundaryBlockKey,\n+        boundaryOffset,\n+        nextBlockKey,\n+        nextOffset,\n+        limitedToSingleBlock,\n+        contentState\n+    );\n+}\n+\n+function expandLeftSingleCursor(\n+    stretchLeft,\n+    boundaryBlockKey,\n+    boundaryOffset,\n+    currentBlockKey,\n+    currentOffset,\n+    limitedToSingleBlock,\n+    contentState\n+) {\n+    const boundaryViolated = currentBlockKey === boundaryBlockKey && currentOffset - stretchLeft <= boundaryOffset;\n+\n+    if (boundaryViolated) {\n+        return {\n+            blockKey: boundaryBlockKey,\n+            offset: boundaryOffset\n+        };\n+    }\n+\n+    // check if resizing can be resolved in the current block\n+\n+    if (currentOffset - stretchLeft >= 0) {\n+        return {\n+            blockKey: currentBlockKey,\n+            offset: currentOffset - stretchLeft\n+        };\n+    }\n+\n+    // jump to the end of the block before\n+\n+    const blockBefore = contentState.getBlockBefore(currentBlockKey);\n+\n+    if (blockBefore === null || blockBefore === undefined || limitedToSingleBlock) {\n+        return {\n+            blockKey: currentBlockKey,\n+            offset: 0\n+        };\n+    }\n+\n+    const nextStretchLeft = stretchLeft - currentOffset;\n+    const nextOffset = blockBefore.getLength();\n+    const nextBlockKey = blockBefore.getKey();\n+\n+    return expandLeftSingleCursor(\n+        nextStretchLeft,\n+        boundaryBlockKey,\n+        boundaryOffset,\n+        nextBlockKey,\n+        nextOffset,\n+        limitedToSingleBlock,\n+        contentState\n+    );\n+}\n+\n+export function resizeDraftSelection(stretchLeft, stretchRight, selection, editorState, limitedToSingleBlock = false) {\n+    const contentState = editorState.getCurrentContent();\n+    const firstBlock = contentState.getFirstBlock();\n+    const lastBlock = contentState.getLastBlock();\n+\n+    // shrinking is performed by extending in the opposite direction\n+    const shrinkLeft = stretchLeft < 0;\n+    const nextLeft = shrinkLeft\n+        ? expandRightSingleCursor(","path":"scripts/core/editor3/helpers/resizeDraftSelection.js","position":117,"original_position":117,"commit_id":"2b1cce03014b7be9c38d87db5e321f6255a44db0","original_commit_id":"2b1cce03014b7be9c38d87db5e321f6255a44db0","user":{"login":"tomaskikutis","id":2076953,"avatar_url":"https://avatars0.githubusercontent.com/u/2076953?v=4","gravatar_id":"","url":"https://api.github.com/users/tomaskikutis","html_url":"https://github.com/tomaskikutis","followers_url":"https://api.github.com/users/tomaskikutis/followers","following_url":"https://api.github.com/users/tomaskikutis/following{/other_user}","gists_url":"https://api.github.com/users/tomaskikutis/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaskikutis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaskikutis/subscriptions","organizations_url":"https://api.github.com/users/tomaskikutis/orgs","repos_url":"https://api.github.com/users/tomaskikutis/repos","events_url":"https://api.github.com/users/tomaskikutis/events{/privacy}","received_events_url":"https://api.github.com/users/tomaskikutis/received_events","type":"User","site_admin":false},"body":"You're right about the offset, I don't know why I expected it to start from focus offset.\r\n\r\nI also agree avoiding code duplication and propose that I remove `getBlockAndOffset` and replace it with `expandLeftSingleCursor` in all places it's used. Is that alright?\r\n\r\nI believe I found a real bug this time.When calling `getBlockAndOffset`, with a selection start on 0, and are trying to go -1, the selection jumps to the previous block correctly, but instead of stopping at the last position, which would be 30 in this case, it goes to 28. Do you think it would cause problems in the code using `getBlockAndOffset` if I replaced it to `expandLeftSingleCursor` ?","created_at":"2018-03-16T13:00:13Z","updated_at":"2018-03-16T13:00:13Z","html_url":"https://github.com/superdesk/superdesk-client-core/pull/2153#discussion_r175081418","pull_request_url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/comments/175081418"},"html":{"href":"https://github.com/superdesk/superdesk-client-core/pull/2153#discussion_r175081418"},"pull_request":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153"}},"in_reply_to_id":175017674},"pull_request":{"url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153","id":175456938,"html_url":"https://github.com/superdesk/superdesk-client-core/pull/2153","diff_url":"https://github.com/superdesk/superdesk-client-core/pull/2153.diff","patch_url":"https://github.com/superdesk/superdesk-client-core/pull/2153.patch","issue_url":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/2153","number":2153,"state":"open","locked":false,"title":"Implement resizing draft-js selection","user":{"login":"tomaskikutis","id":2076953,"avatar_url":"https://avatars0.githubusercontent.com/u/2076953?v=4","gravatar_id":"","url":"https://api.github.com/users/tomaskikutis","html_url":"https://github.com/tomaskikutis","followers_url":"https://api.github.com/users/tomaskikutis/followers","following_url":"https://api.github.com/users/tomaskikutis/following{/other_user}","gists_url":"https://api.github.com/users/tomaskikutis/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaskikutis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaskikutis/subscriptions","organizations_url":"https://api.github.com/users/tomaskikutis/orgs","repos_url":"https://api.github.com/users/tomaskikutis/repos","events_url":"https://api.github.com/users/tomaskikutis/events{/privacy}","received_events_url":"https://api.github.com/users/tomaskikutis/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-03-16T07:17:23Z","updated_at":"2018-03-16T13:00:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69d93020d39cdc1d1af1b619cce30f845e8c5fad","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/superdesk/superdesk-client-core/milestones/27","html_url":"https://github.com/superdesk/superdesk-client-core/milestone/27","labels_url":"https://api.github.com/repos/superdesk/superdesk-client-core/milestones/27/labels","id":3155804,"number":27,"title":"1.15","description":"","creator":{"login":"petrjasek","id":179249,"avatar_url":"https://avatars1.githubusercontent.com/u/179249?v=4","gravatar_id":"","url":"https://api.github.com/users/petrjasek","html_url":"https://github.com/petrjasek","followers_url":"https://api.github.com/users/petrjasek/followers","following_url":"https://api.github.com/users/petrjasek/following{/other_user}","gists_url":"https://api.github.com/users/petrjasek/gists{/gist_id}","starred_url":"https://api.github.com/users/petrjasek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrjasek/subscriptions","organizations_url":"https://api.github.com/users/petrjasek/orgs","repos_url":"https://api.github.com/users/petrjasek/repos","events_url":"https://api.github.com/users/petrjasek/events{/privacy}","received_events_url":"https://api.github.com/users/petrjasek/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":35,"state":"open","created_at":"2018-03-02T10:28:29Z","updated_at":"2018-03-16T08:44:50Z","due_on":"2018-03-16T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153/commits","review_comments_url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153/comments","review_comment_url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/2153/comments","statuses_url":"https://api.github.com/repos/superdesk/superdesk-client-core/statuses/2b1cce03014b7be9c38d87db5e321f6255a44db0","head":{"label":"tomaskikutis:implement-resizing-selection","ref":"implement-resizing-selection","sha":"2b1cce03014b7be9c38d87db5e321f6255a44db0","user":{"login":"tomaskikutis","id":2076953,"avatar_url":"https://avatars0.githubusercontent.com/u/2076953?v=4","gravatar_id":"","url":"https://api.github.com/users/tomaskikutis","html_url":"https://github.com/tomaskikutis","followers_url":"https://api.github.com/users/tomaskikutis/followers","following_url":"https://api.github.com/users/tomaskikutis/following{/other_user}","gists_url":"https://api.github.com/users/tomaskikutis/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaskikutis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaskikutis/subscriptions","organizations_url":"https://api.github.com/users/tomaskikutis/orgs","repos_url":"https://api.github.com/users/tomaskikutis/repos","events_url":"https://api.github.com/users/tomaskikutis/events{/privacy}","received_events_url":"https://api.github.com/users/tomaskikutis/received_events","type":"User","site_admin":false},"repo":{"id":118113228,"name":"superdesk-client-core","full_name":"tomaskikutis/superdesk-client-core","owner":{"login":"tomaskikutis","id":2076953,"avatar_url":"https://avatars0.githubusercontent.com/u/2076953?v=4","gravatar_id":"","url":"https://api.github.com/users/tomaskikutis","html_url":"https://github.com/tomaskikutis","followers_url":"https://api.github.com/users/tomaskikutis/followers","following_url":"https://api.github.com/users/tomaskikutis/following{/other_user}","gists_url":"https://api.github.com/users/tomaskikutis/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaskikutis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaskikutis/subscriptions","organizations_url":"https://api.github.com/users/tomaskikutis/orgs","repos_url":"https://api.github.com/users/tomaskikutis/repos","events_url":"https://api.github.com/users/tomaskikutis/events{/privacy}","received_events_url":"https://api.github.com/users/tomaskikutis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tomaskikutis/superdesk-client-core","description":"Common client modules for superdesk apps.","fork":true,"url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core","forks_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/forks","keys_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/teams","hooks_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/hooks","issue_events_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/issues/events{/number}","events_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/events","assignees_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/assignees{/user}","branches_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/branches{/branch}","tags_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/tags","blobs_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/statuses/{sha}","languages_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/languages","stargazers_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/stargazers","contributors_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/contributors","subscribers_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/subscribers","subscription_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/subscription","commits_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/contents/{+path}","compare_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/merges","archive_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/downloads","issues_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/issues{/number}","pulls_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/pulls{/number}","milestones_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/milestones{/number}","notifications_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/labels{/name}","releases_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/releases{/id}","deployments_url":"https://api.github.com/repos/tomaskikutis/superdesk-client-core/deployments","created_at":"2018-01-19T10:43:33Z","updated_at":"2018-03-14T06:01:36Z","pushed_at":"2018-03-16T08:35:19Z","git_url":"git://github.com/tomaskikutis/superdesk-client-core.git","ssh_url":"git@github.com:tomaskikutis/superdesk-client-core.git","clone_url":"https://github.com/tomaskikutis/superdesk-client-core.git","svn_url":"https://github.com/tomaskikutis/superdesk-client-core","homepage":"","size":13421,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"superdesk:master","ref":"master","sha":"2b9916bb8f205e620c29052a0e1b6606a722e5a2","user":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars2.githubusercontent.com/u/5527298?v=4","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"repo":{"id":50631400,"name":"superdesk-client-core","full_name":"superdesk/superdesk-client-core","owner":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars2.githubusercontent.com/u/5527298?v=4","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/superdesk/superdesk-client-core","description":"Common client modules for superdesk apps.","fork":false,"url":"https://api.github.com/repos/superdesk/superdesk-client-core","forks_url":"https://api.github.com/repos/superdesk/superdesk-client-core/forks","keys_url":"https://api.github.com/repos/superdesk/superdesk-client-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/superdesk/superdesk-client-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/superdesk/superdesk-client-core/teams","hooks_url":"https://api.github.com/repos/superdesk/superdesk-client-core/hooks","issue_events_url":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/events{/number}","events_url":"https://api.github.com/repos/superdesk/superdesk-client-core/events","assignees_url":"https://api.github.com/repos/superdesk/superdesk-client-core/assignees{/user}","branches_url":"https://api.github.com/repos/superdesk/superdesk-client-core/branches{/branch}","tags_url":"https://api.github.com/repos/superdesk/superdesk-client-core/tags","blobs_url":"https://api.github.com/repos/superdesk/superdesk-client-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/superdesk/superdesk-client-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/superdesk/superdesk-client-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/superdesk/superdesk-client-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/superdesk/superdesk-client-core/statuses/{sha}","languages_url":"https://api.github.com/repos/superdesk/superdesk-client-core/languages","stargazers_url":"https://api.github.com/repos/superdesk/superdesk-client-core/stargazers","contributors_url":"https://api.github.com/repos/superdesk/superdesk-client-core/contributors","subscribers_url":"https://api.github.com/repos/superdesk/superdesk-client-core/subscribers","subscription_url":"https://api.github.com/repos/superdesk/superdesk-client-core/subscription","commits_url":"https://api.github.com/repos/superdesk/superdesk-client-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/superdesk/superdesk-client-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/superdesk/superdesk-client-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/superdesk/superdesk-client-core/contents/{+path}","compare_url":"https://api.github.com/repos/superdesk/superdesk-client-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/superdesk/superdesk-client-core/merges","archive_url":"https://api.github.com/repos/superdesk/superdesk-client-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/superdesk/superdesk-client-core/downloads","issues_url":"https://api.github.com/repos/superdesk/superdesk-client-core/issues{/number}","pulls_url":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls{/number}","milestones_url":"https://api.github.com/repos/superdesk/superdesk-client-core/milestones{/number}","notifications_url":"https://api.github.com/repos/superdesk/superdesk-client-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/superdesk/superdesk-client-core/labels{/name}","releases_url":"https://api.github.com/repos/superdesk/superdesk-client-core/releases{/id}","deployments_url":"https://api.github.com/repos/superdesk/superdesk-client-core/deployments","created_at":"2016-01-29T02:33:16Z","updated_at":"2018-03-16T08:43:28Z","pushed_at":"2018-03-16T08:43:27Z","git_url":"git://github.com/superdesk/superdesk-client-core.git","ssh_url":"git@github.com:superdesk/superdesk-client-core.git","clone_url":"https://github.com/superdesk/superdesk-client-core.git","svn_url":"https://github.com/superdesk/superdesk-client-core","homepage":"","size":13184,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":50,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":50,"open_issues":6,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153"},"html":{"href":"https://github.com/superdesk/superdesk-client-core/pull/2153"},"issue":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/2153"},"comments":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/issues/2153/comments"},"review_comments":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153/comments"},"review_comment":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/pulls/2153/commits"},"statuses":{"href":"https://api.github.com/repos/superdesk/superdesk-client-core/statuses/2b1cce03014b7be9c38d87db5e321f6255a44db0"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"tomaskikutis"}}