{"action":"created","issue":{"url":"https://api.github.com/repos/philc/vimium/issues/1769","labels_url":"https://api.github.com/repos/philc/vimium/issues/1769/labels{/name}","comments_url":"https://api.github.com/repos/philc/vimium/issues/1769/comments","events_url":"https://api.github.com/repos/philc/vimium/issues/1769/events","html_url":"https://github.com/philc/vimium/issues/1769","id":95666569,"number":1769,"title":"Link hints handling","user":{"login":"terraqout","id":1011721,"avatar_url":"https://avatars.githubusercontent.com/u/1011721?v=3","gravatar_id":"","url":"https://api.github.com/users/terraqout","html_url":"https://github.com/terraqout","followers_url":"https://api.github.com/users/terraqout/followers","following_url":"https://api.github.com/users/terraqout/following{/other_user}","gists_url":"https://api.github.com/users/terraqout/gists{/gist_id}","starred_url":"https://api.github.com/users/terraqout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terraqout/subscriptions","organizations_url":"https://api.github.com/users/terraqout/orgs","repos_url":"https://api.github.com/users/terraqout/repos","events_url":"https://api.github.com/users/terraqout/events{/privacy}","received_events_url":"https://api.github.com/users/terraqout/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-17T14:22:28Z","updated_at":"2015-07-17T16:16:39Z","closed_at":null,"body":"I don't like the way selection of links  when using open link feature.\r\nI'll explain with Jira page (which I hate and use everyday):\r\n\r\n![jira](https://cloud.githubusercontent.com/assets/1011721/8749070/9d055e94-2ca7-11e5-965f-8eb9ffb878e3.png)\r\n\r\non this page I press f(to call open links) and \"sta\" to press \"start\". What I see unexpected:\r\n1. Shortest label should be more preferable\r\n2. Position of word should play role in ranking: 'sta' is for \"start\", and not for 'inSTAgram'\r\n3. Top-down if rank are equal\r\n\r\nI can implement it by myself with ease, but if this would find a relevant answer from community. So let's discuss"},"comment":{"url":"https://api.github.com/repos/philc/vimium/issues/comments/122330821","html_url":"https://github.com/philc/vimium/issues/1769#issuecomment-122330821","issue_url":"https://api.github.com/repos/philc/vimium/issues/1769","id":122330821,"user":{"login":"mrmr1993","id":1847343,"avatar_url":"https://avatars.githubusercontent.com/u/1847343?v=3","gravatar_id":"","url":"https://api.github.com/users/mrmr1993","html_url":"https://github.com/mrmr1993","followers_url":"https://api.github.com/users/mrmr1993/followers","following_url":"https://api.github.com/users/mrmr1993/following{/other_user}","gists_url":"https://api.github.com/users/mrmr1993/gists{/gist_id}","starred_url":"https://api.github.com/users/mrmr1993/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrmr1993/subscriptions","organizations_url":"https://api.github.com/users/mrmr1993/orgs","repos_url":"https://api.github.com/users/mrmr1993/repos","events_url":"https://api.github.com/users/mrmr1993/events{/privacy}","received_events_url":"https://api.github.com/users/mrmr1993/received_events","type":"User","site_admin":false},"created_at":"2015-07-17T16:16:39Z","updated_at":"2015-07-17T16:16:39Z","body":"[This line here](https://github.com/philc/vimium/blob/master/content_scripts/link_hints.coffee#L574) is responsible for sorting, and [this function](https://github.com/philc/vimium/blob/master/content_scripts/link_hints.coffee#L587) is responsible for generating the scores on which we sort.\r\n\r\n\r\n> 1\\. Shortest label should be more preferable\r\n\r\nThis should be easily handled by changing the sorting code to\r\n\r\n```coffee\r\nhintMarkers = hintMarkers[..].sort (a,b) -> b.score - a.score || b.linkText.length - a.linkText.length\r\n```\r\n\r\nCan you think of any cases where this wouldn't be the right thing to do? In general, this might be confusing because it doesn't respect the order of hints, but I never use this mode, so I don't know.\r\n\r\n> 2\\. Position of word should play role in ranking: 'sta' is for \"start\", and not for 'inSTAgram'\r\n\r\nThe code for the scores seems to already do this.\r\n\r\n> 3\\. Top-down if rank are equal\r\n\r\nI think the reason this isn't already the case seems to be Chrome's `Array.prototype.sort ` implementation; hints which score equally may be reordered by `sort`, as seems to be happening here. I expect that storing the original index of each hint and also comparing on that will work.\r\n\r\nSo, my proposed solution is to replace the sorting code with:\r\n\r\n```coffee\r\nhintMarker.originalIndex = i for hintMarker, i in hintMarkers\r\nhintMarkers = hintMarkers[..].sort (a,b) -> b.score - a.score || b.linkText.length - a.linkText.length || b.originalIndex - a.originalIndex\r\n```\r\n\r\nThoughts? "}}