{"action":"created","issue":{"url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/397","repository_url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit","labels_url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/397/labels{/name}","comments_url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/397/comments","events_url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/397/events","html_url":"https://github.com/bustlelabs/mobiledoc-kit/pull/397","id":154505806,"number":397,"title":"Prevent 'Invalid argument' error when triple-clicking to select on IE","user":{"login":"YoranBrondsema","id":1374412,"avatar_url":"https://avatars.githubusercontent.com/u/1374412?v=3","gravatar_id":"","url":"https://api.github.com/users/YoranBrondsema","html_url":"https://github.com/YoranBrondsema","followers_url":"https://api.github.com/users/YoranBrondsema/followers","following_url":"https://api.github.com/users/YoranBrondsema/following{/other_user}","gists_url":"https://api.github.com/users/YoranBrondsema/gists{/gist_id}","starred_url":"https://api.github.com/users/YoranBrondsema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YoranBrondsema/subscriptions","organizations_url":"https://api.github.com/users/YoranBrondsema/orgs","repos_url":"https://api.github.com/users/YoranBrondsema/repos","events_url":"https://api.github.com/users/YoranBrondsema/events{/privacy}","received_events_url":"https://api.github.com/users/YoranBrondsema/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-12T15:04:02Z","updated_at":"2016-05-12T18:06:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/pulls/397","html_url":"https://github.com/bustlelabs/mobiledoc-kit/pull/397","diff_url":"https://github.com/bustlelabs/mobiledoc-kit/pull/397.diff","patch_url":"https://github.com/bustlelabs/mobiledoc-kit/pull/397.patch"},"body":"On IE11 and Edge, triple-clicking on `This is Mobiledoc-kit` on the [demo](https://bustlelabs.github.io/mobiledoc-kit/demo/) to select it throws an `Invalid argument` error.\r\n\r\nThe reason is that an `undefined` value for `focusNode` is given as an argument to `compareDocumentPosition` on https://github.com/bustlelabs/mobiledoc-kit/blob/0f6d2324fe23b10de0783483ee01163a7d8d4236/src/js/utils/selection-utils.js#L87. I traced it back to it happening in the recursive call https://github.com/bustlelabs/mobiledoc-kit/blob/0f6d2324fe23b10de0783483ee01163a7d8d4236/src/js/utils/selection-utils.js#L102.\r\n\r\nThe problem is that in the outer call, `focusNode` is set to the editor `<div>` element with a `focusOffset` of 2. Then `focusNode.childNodes[focusOffset]` is `undefined` as it only contains 2 elements. I looked up why IE does this but couldn't find anything.\r\n\r\nAs a solution, when such a case happens, I set the focus to the very last character in the node. I think that achieves the intent."},"comment":{"url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/comments/218838584","html_url":"https://github.com/bustlelabs/mobiledoc-kit/pull/397#issuecomment-218838584","issue_url":"https://api.github.com/repos/bustlelabs/mobiledoc-kit/issues/397","id":218838584,"user":{"login":"bantic","id":2023,"avatar_url":"https://avatars.githubusercontent.com/u/2023?v=3","gravatar_id":"","url":"https://api.github.com/users/bantic","html_url":"https://github.com/bantic","followers_url":"https://api.github.com/users/bantic/followers","following_url":"https://api.github.com/users/bantic/following{/other_user}","gists_url":"https://api.github.com/users/bantic/gists{/gist_id}","starred_url":"https://api.github.com/users/bantic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bantic/subscriptions","organizations_url":"https://api.github.com/users/bantic/orgs","repos_url":"https://api.github.com/users/bantic/repos","events_url":"https://api.github.com/users/bantic/events{/privacy}","received_events_url":"https://api.github.com/users/bantic/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T18:06:57Z","updated_at":"2016-05-12T18:06:57Z","body":"@YoranBrondsema great investigation, thank you very much!"}}