{"action":"created","issue":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/782","labels_url":"https://api.github.com/repos/lhorie/mithril.js/issues/782/labels{/name}","comments_url":"https://api.github.com/repos/lhorie/mithril.js/issues/782/comments","events_url":"https://api.github.com/repos/lhorie/mithril.js/issues/782/events","html_url":"https://github.com/lhorie/mithril.js/issues/782","id":103703561,"number":782,"title":"Implement some sort of React's restoreSelection()","user":{"login":"avesus","id":4148259,"avatar_url":"https://avatars.githubusercontent.com/u/4148259?v=3","gravatar_id":"","url":"https://api.github.com/users/avesus","html_url":"https://github.com/avesus","followers_url":"https://api.github.com/users/avesus/followers","following_url":"https://api.github.com/users/avesus/following{/other_user}","gists_url":"https://api.github.com/users/avesus/gists{/gist_id}","starred_url":"https://api.github.com/users/avesus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avesus/subscriptions","organizations_url":"https://api.github.com/users/avesus/orgs","repos_url":"https://api.github.com/users/avesus/repos","events_url":"https://api.github.com/users/avesus/events{/privacy}","received_events_url":"https://api.github.com/users/avesus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-28T11:43:39Z","updated_at":"2015-08-28T18:15:48Z","closed_at":null,"body":"React uses `restoreSelection()` method to restore selection when complex reordering makes happen.\r\nhttps://github.com/facebook/react/blob/master/src/renderers/dom/client/ReactInputSelection.js\r\n\r\nMithril doesn't, which leads to focus and selection lost when reordering happens, i.e.\r\n\r\nStep 1:\r\n ``` html\r\n<textarea id=\"1\"/>\r\n<textarea id=\"2\"/>\r\n```\r\nFocus in 1, some text selected.\r\n\r\nStep 2: change sort order\r\n``` html\r\n<textarea id=\"2\"/>\r\n<textarea id=\"1\"/>\r\n```\r\nFocus in 1, some text selected. All works as expected.\r\n\r\nStep 3: change sort order again\r\n``` html\r\n<textarea id=\"1\"/>\r\n<textarea id=\"2\"/>\r\n```\r\nFocus lost, selection lost."},"comment":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/comments/135851708","html_url":"https://github.com/lhorie/mithril.js/issues/782#issuecomment-135851708","issue_url":"https://api.github.com/repos/lhorie/mithril.js/issues/782","id":135851708,"user":{"login":"impinball","id":4483844,"avatar_url":"https://avatars.githubusercontent.com/u/4483844?v=3","gravatar_id":"","url":"https://api.github.com/users/impinball","html_url":"https://github.com/impinball","followers_url":"https://api.github.com/users/impinball/followers","following_url":"https://api.github.com/users/impinball/following{/other_user}","gists_url":"https://api.github.com/users/impinball/gists{/gist_id}","starred_url":"https://api.github.com/users/impinball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/impinball/subscriptions","organizations_url":"https://api.github.com/users/impinball/orgs","repos_url":"https://api.github.com/users/impinball/repos","events_url":"https://api.github.com/users/impinball/events{/privacy}","received_events_url":"https://api.github.com/users/impinball/received_events","type":"User","site_admin":false},"created_at":"2015-08-28T18:15:48Z","updated_at":"2015-08-28T18:15:48Z","body":"This sounds more like a bug than a feature request. I don't know much about Mithril's diff algorithm, though, but that's where the bug most likely is. The diff should still respect the `key` name, especially if it's in the same relative section. Is the component itself being replaced at this point? You can use this as an attribute to check for that:\r\n\r\n```js\r\n// Your return `view` for the container holding the list\r\nm(\"div\", {\r\n  // props...\r\n  config: function (elem, isInit, context) {\r\n    context.onunload = function () {\r\n      console.log(\"Element unloaded!\")\r\n    }\r\n  },\r\n}, body)\r\n```"}}