{"action":"created","comment":{"url":"https://api.github.com/repos/yabwe/medium-editor/pulls/comments/47634800","id":47634800,"diff_hunk":"@@ -89,26 +98,55 @@\n                 nodeStack = [],\n                 charIndex = 0,\n                 foundStart = false,\n+                foundEnd = false,\n+                trailingImageCount = 0,\n                 stop = false,\n                 nextCharIndex;\n \n             while (!stop && node) {\n-                if (node.nodeType === 3) {\n-                    nextCharIndex = charIndex + node.length;\n-                    if (!foundStart && selectionState.start >= charIndex && selectionState.start <= nextCharIndex) {\n-                        range.setStart(node, selectionState.start - charIndex);\n-                        foundStart = true;\n-                    }\n-                    if (foundStart && selectionState.end >= charIndex && selectionState.end <= nextCharIndex) {\n-                        range.setEnd(node, selectionState.end - charIndex);\n-                        stop = true;\n-                    }\n-                    charIndex = nextCharIndex;\n-                } else {\n-                    var i = node.childNodes.length - 1;\n-                    while (i >= 0) {\n-                        nodeStack.push(node.childNodes[i]);\n-                        i -= 1;\n+                // Only iterate over elements and text nodes\n+                if (node.nodeType <= 3) {","path":"src/js/selection.js","position":43,"original_position":43,"commit_id":"cf1a9e28f6c8c26dc9e4758e6fc89ecd418a7f01","original_commit_id":"cf1a9e28f6c8c26dc9e4758e6fc89ecd418a7f01","user":{"login":"nmielnik","id":2444240,"avatar_url":"https://avatars.githubusercontent.com/u/2444240?v=3","gravatar_id":"","url":"https://api.github.com/users/nmielnik","html_url":"https://github.com/nmielnik","followers_url":"https://api.github.com/users/nmielnik/followers","following_url":"https://api.github.com/users/nmielnik/following{/other_user}","gists_url":"https://api.github.com/users/nmielnik/gists{/gist_id}","starred_url":"https://api.github.com/users/nmielnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmielnik/subscriptions","organizations_url":"https://api.github.com/users/nmielnik/orgs","repos_url":"https://api.github.com/users/nmielnik/repos","events_url":"https://api.github.com/users/nmielnik/events{/privacy}","received_events_url":"https://api.github.com/users/nmielnik/received_events","type":"User","site_admin":false},"body":"doh, I'm not a big fan of it either. Fixing it now","created_at":"2015-12-15T13:25:52Z","updated_at":"2015-12-15T13:25:52Z","html_url":"https://github.com/yabwe/medium-editor/pull/904#discussion_r47634800","pull_request_url":"https://api.github.com/repos/yabwe/medium-editor/pulls/904","_links":{"self":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/comments/47634800"},"html":{"href":"https://github.com/yabwe/medium-editor/pull/904#discussion_r47634800"},"pull_request":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/904"}}},"pull_request":{"url":"https://api.github.com/repos/yabwe/medium-editor/pulls/904","id":52750437,"html_url":"https://github.com/yabwe/medium-editor/pull/904","diff_url":"https://github.com/yabwe/medium-editor/pull/904.diff","patch_url":"https://github.com/yabwe/medium-editor/pull/904.patch","issue_url":"https://api.github.com/repos/yabwe/medium-editor/issues/904","number":904,"state":"open","locked":false,"title":"Fix issue with image-only selections","user":{"login":"nmielnik","id":2444240,"avatar_url":"https://avatars.githubusercontent.com/u/2444240?v=3","gravatar_id":"","url":"https://api.github.com/users/nmielnik","html_url":"https://github.com/nmielnik","followers_url":"https://api.github.com/users/nmielnik/followers","following_url":"https://api.github.com/users/nmielnik/following{/other_user}","gists_url":"https://api.github.com/users/nmielnik/gists{/gist_id}","starred_url":"https://api.github.com/users/nmielnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmielnik/subscriptions","organizations_url":"https://api.github.com/users/nmielnik/orgs","repos_url":"https://api.github.com/users/nmielnik/repos","events_url":"https://api.github.com/users/nmielnik/events{/privacy}","received_events_url":"https://api.github.com/users/nmielnik/received_events","type":"User","site_admin":false},"body":"Currently, medium-editor does not sufficiently handle exporting/importing selections that contain only an image (it's kind of supported in some browsers, but completely busted in IE). Images are a specific problem because:\r\n\r\n1. `<img>` elements are not text-nodes _(the code only handled selections that span 1 or more text nodes)_\r\n2. `<img>` elements are elements that will never have children _(the code ignored any element without children)_\r\n3. `<img>` elements have empty textContent _(the code depends on content having length so it can store the beginning and end of a selection)_\r\n\r\nmedium-editor handles exporting/importing selections based on the number of characters and paragraphs are before and after the selection.  So, if the selection contains only an image, when attempting to restore the selection the code ends up with a collapse selection.\r\n\r\nThe fixes here allow for wrapping an image in a link, and changing the url of a link on just an image.  This behavior was partially introduce by #803 but the behavior was broken in phantom (preventing extensive tests from being added) and was also broken in IE11 (causing test failures for the entire project).\r\n\r\nBy fixing this, this fixes the test failures in IE11.","created_at":"2015-12-05T08:31:06Z","updated_at":"2015-12-15T13:25:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d9c21f9b9a1bded91d43d2fbc7198fca04a48098","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yabwe/medium-editor/pulls/904/commits","review_comments_url":"https://api.github.com/repos/yabwe/medium-editor/pulls/904/comments","review_comment_url":"https://api.github.com/repos/yabwe/medium-editor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yabwe/medium-editor/issues/904/comments","statuses_url":"https://api.github.com/repos/yabwe/medium-editor/statuses/cf1a9e28f6c8c26dc9e4758e6fc89ecd418a7f01","head":{"label":"yabwe:image-only-selection","ref":"image-only-selection","sha":"cf1a9e28f6c8c26dc9e4758e6fc89ecd418a7f01","user":{"login":"yabwe","id":12655868,"avatar_url":"https://avatars.githubusercontent.com/u/12655868?v=3","gravatar_id":"","url":"https://api.github.com/users/yabwe","html_url":"https://github.com/yabwe","followers_url":"https://api.github.com/users/yabwe/followers","following_url":"https://api.github.com/users/yabwe/following{/other_user}","gists_url":"https://api.github.com/users/yabwe/gists{/gist_id}","starred_url":"https://api.github.com/users/yabwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yabwe/subscriptions","organizations_url":"https://api.github.com/users/yabwe/orgs","repos_url":"https://api.github.com/users/yabwe/repos","events_url":"https://api.github.com/users/yabwe/events{/privacy}","received_events_url":"https://api.github.com/users/yabwe/received_events","type":"Organization","site_admin":false},"repo":{"id":10365411,"name":"medium-editor","full_name":"yabwe/medium-editor","owner":{"login":"yabwe","id":12655868,"avatar_url":"https://avatars.githubusercontent.com/u/12655868?v=3","gravatar_id":"","url":"https://api.github.com/users/yabwe","html_url":"https://github.com/yabwe","followers_url":"https://api.github.com/users/yabwe/followers","following_url":"https://api.github.com/users/yabwe/following{/other_user}","gists_url":"https://api.github.com/users/yabwe/gists{/gist_id}","starred_url":"https://api.github.com/users/yabwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yabwe/subscriptions","organizations_url":"https://api.github.com/users/yabwe/orgs","repos_url":"https://api.github.com/users/yabwe/repos","events_url":"https://api.github.com/users/yabwe/events{/privacy}","received_events_url":"https://api.github.com/users/yabwe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yabwe/medium-editor","description":"Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.","fork":false,"url":"https://api.github.com/repos/yabwe/medium-editor","forks_url":"https://api.github.com/repos/yabwe/medium-editor/forks","keys_url":"https://api.github.com/repos/yabwe/medium-editor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yabwe/medium-editor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yabwe/medium-editor/teams","hooks_url":"https://api.github.com/repos/yabwe/medium-editor/hooks","issue_events_url":"https://api.github.com/repos/yabwe/medium-editor/issues/events{/number}","events_url":"https://api.github.com/repos/yabwe/medium-editor/events","assignees_url":"https://api.github.com/repos/yabwe/medium-editor/assignees{/user}","branches_url":"https://api.github.com/repos/yabwe/medium-editor/branches{/branch}","tags_url":"https://api.github.com/repos/yabwe/medium-editor/tags","blobs_url":"https://api.github.com/repos/yabwe/medium-editor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yabwe/medium-editor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yabwe/medium-editor/git/refs{/sha}","trees_url":"https://api.github.com/repos/yabwe/medium-editor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yabwe/medium-editor/statuses/{sha}","languages_url":"https://api.github.com/repos/yabwe/medium-editor/languages","stargazers_url":"https://api.github.com/repos/yabwe/medium-editor/stargazers","contributors_url":"https://api.github.com/repos/yabwe/medium-editor/contributors","subscribers_url":"https://api.github.com/repos/yabwe/medium-editor/subscribers","subscription_url":"https://api.github.com/repos/yabwe/medium-editor/subscription","commits_url":"https://api.github.com/repos/yabwe/medium-editor/commits{/sha}","git_commits_url":"https://api.github.com/repos/yabwe/medium-editor/git/commits{/sha}","comments_url":"https://api.github.com/repos/yabwe/medium-editor/comments{/number}","issue_comment_url":"https://api.github.com/repos/yabwe/medium-editor/issues/comments{/number}","contents_url":"https://api.github.com/repos/yabwe/medium-editor/contents/{+path}","compare_url":"https://api.github.com/repos/yabwe/medium-editor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yabwe/medium-editor/merges","archive_url":"https://api.github.com/repos/yabwe/medium-editor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yabwe/medium-editor/downloads","issues_url":"https://api.github.com/repos/yabwe/medium-editor/issues{/number}","pulls_url":"https://api.github.com/repos/yabwe/medium-editor/pulls{/number}","milestones_url":"https://api.github.com/repos/yabwe/medium-editor/milestones{/number}","notifications_url":"https://api.github.com/repos/yabwe/medium-editor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yabwe/medium-editor/labels{/name}","releases_url":"https://api.github.com/repos/yabwe/medium-editor/releases{/id}","created_at":"2013-05-29T17:40:11Z","updated_at":"2015-12-15T11:38:57Z","pushed_at":"2015-12-15T13:19:58Z","git_url":"git://github.com/yabwe/medium-editor.git","ssh_url":"git@github.com:yabwe/medium-editor.git","clone_url":"https://github.com/yabwe/medium-editor.git","svn_url":"https://github.com/yabwe/medium-editor","homepage":"https://yabwe.github.io/medium-editor/","size":8279,"stargazers_count":6065,"watchers_count":6065,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":768,"mirror_url":null,"open_issues_count":111,"forks":768,"open_issues":111,"watchers":6065,"default_branch":"master"}},"base":{"label":"yabwe:master","ref":"master","sha":"5ae7356f6d3318e3ef6feed81f8ff150704e4cba","user":{"login":"yabwe","id":12655868,"avatar_url":"https://avatars.githubusercontent.com/u/12655868?v=3","gravatar_id":"","url":"https://api.github.com/users/yabwe","html_url":"https://github.com/yabwe","followers_url":"https://api.github.com/users/yabwe/followers","following_url":"https://api.github.com/users/yabwe/following{/other_user}","gists_url":"https://api.github.com/users/yabwe/gists{/gist_id}","starred_url":"https://api.github.com/users/yabwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yabwe/subscriptions","organizations_url":"https://api.github.com/users/yabwe/orgs","repos_url":"https://api.github.com/users/yabwe/repos","events_url":"https://api.github.com/users/yabwe/events{/privacy}","received_events_url":"https://api.github.com/users/yabwe/received_events","type":"Organization","site_admin":false},"repo":{"id":10365411,"name":"medium-editor","full_name":"yabwe/medium-editor","owner":{"login":"yabwe","id":12655868,"avatar_url":"https://avatars.githubusercontent.com/u/12655868?v=3","gravatar_id":"","url":"https://api.github.com/users/yabwe","html_url":"https://github.com/yabwe","followers_url":"https://api.github.com/users/yabwe/followers","following_url":"https://api.github.com/users/yabwe/following{/other_user}","gists_url":"https://api.github.com/users/yabwe/gists{/gist_id}","starred_url":"https://api.github.com/users/yabwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yabwe/subscriptions","organizations_url":"https://api.github.com/users/yabwe/orgs","repos_url":"https://api.github.com/users/yabwe/repos","events_url":"https://api.github.com/users/yabwe/events{/privacy}","received_events_url":"https://api.github.com/users/yabwe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yabwe/medium-editor","description":"Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.","fork":false,"url":"https://api.github.com/repos/yabwe/medium-editor","forks_url":"https://api.github.com/repos/yabwe/medium-editor/forks","keys_url":"https://api.github.com/repos/yabwe/medium-editor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yabwe/medium-editor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yabwe/medium-editor/teams","hooks_url":"https://api.github.com/repos/yabwe/medium-editor/hooks","issue_events_url":"https://api.github.com/repos/yabwe/medium-editor/issues/events{/number}","events_url":"https://api.github.com/repos/yabwe/medium-editor/events","assignees_url":"https://api.github.com/repos/yabwe/medium-editor/assignees{/user}","branches_url":"https://api.github.com/repos/yabwe/medium-editor/branches{/branch}","tags_url":"https://api.github.com/repos/yabwe/medium-editor/tags","blobs_url":"https://api.github.com/repos/yabwe/medium-editor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yabwe/medium-editor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yabwe/medium-editor/git/refs{/sha}","trees_url":"https://api.github.com/repos/yabwe/medium-editor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yabwe/medium-editor/statuses/{sha}","languages_url":"https://api.github.com/repos/yabwe/medium-editor/languages","stargazers_url":"https://api.github.com/repos/yabwe/medium-editor/stargazers","contributors_url":"https://api.github.com/repos/yabwe/medium-editor/contributors","subscribers_url":"https://api.github.com/repos/yabwe/medium-editor/subscribers","subscription_url":"https://api.github.com/repos/yabwe/medium-editor/subscription","commits_url":"https://api.github.com/repos/yabwe/medium-editor/commits{/sha}","git_commits_url":"https://api.github.com/repos/yabwe/medium-editor/git/commits{/sha}","comments_url":"https://api.github.com/repos/yabwe/medium-editor/comments{/number}","issue_comment_url":"https://api.github.com/repos/yabwe/medium-editor/issues/comments{/number}","contents_url":"https://api.github.com/repos/yabwe/medium-editor/contents/{+path}","compare_url":"https://api.github.com/repos/yabwe/medium-editor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yabwe/medium-editor/merges","archive_url":"https://api.github.com/repos/yabwe/medium-editor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yabwe/medium-editor/downloads","issues_url":"https://api.github.com/repos/yabwe/medium-editor/issues{/number}","pulls_url":"https://api.github.com/repos/yabwe/medium-editor/pulls{/number}","milestones_url":"https://api.github.com/repos/yabwe/medium-editor/milestones{/number}","notifications_url":"https://api.github.com/repos/yabwe/medium-editor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yabwe/medium-editor/labels{/name}","releases_url":"https://api.github.com/repos/yabwe/medium-editor/releases{/id}","created_at":"2013-05-29T17:40:11Z","updated_at":"2015-12-15T11:38:57Z","pushed_at":"2015-12-15T13:19:58Z","git_url":"git://github.com/yabwe/medium-editor.git","ssh_url":"git@github.com:yabwe/medium-editor.git","clone_url":"https://github.com/yabwe/medium-editor.git","svn_url":"https://github.com/yabwe/medium-editor","homepage":"https://yabwe.github.io/medium-editor/","size":8279,"stargazers_count":6065,"watchers_count":6065,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":768,"mirror_url":null,"open_issues_count":111,"forks":768,"open_issues":111,"watchers":6065,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/904"},"html":{"href":"https://github.com/yabwe/medium-editor/pull/904"},"issue":{"href":"https://api.github.com/repos/yabwe/medium-editor/issues/904"},"comments":{"href":"https://api.github.com/repos/yabwe/medium-editor/issues/904/comments"},"review_comments":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/904/comments"},"review_comment":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yabwe/medium-editor/pulls/904/commits"},"statuses":{"href":"https://api.github.com/repos/yabwe/medium-editor/statuses/cf1a9e28f6c8c26dc9e4758e6fc89ecd418a7f01"}}}}