{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/pdf.js/pulls/comments/22445307","id":22445307,"diff_hunk":"@@ -0,0 +1,462 @@\n+/*jslint vars: true, nomen: true, plusplus: true, continue:true, forin:true */\n+/*global Node, QNode */\n+\n+/*\n+\n+  Copyright (c) 2014 Michael Sander (speedplane)\n+  Based loosely on code written by (c) 2011 Mike Chambers.","path":"src/core/quadtree.js","position":7,"original_position":7,"commit_id":"34b577d32d300de6c84a92eb1674c7e0d48e343b","original_commit_id":"34b577d32d300de6c84a92eb1674c7e0d48e343b","user":{"login":"speedplane","id":671052,"avatar_url":"https://avatars.githubusercontent.com/u/671052?v=3","gravatar_id":"","url":"https://api.github.com/users/speedplane","html_url":"https://github.com/speedplane","followers_url":"https://api.github.com/users/speedplane/followers","following_url":"https://api.github.com/users/speedplane/following{/other_user}","gists_url":"https://api.github.com/users/speedplane/gists{/gist_id}","starred_url":"https://api.github.com/users/speedplane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/speedplane/subscriptions","organizations_url":"https://api.github.com/users/speedplane/orgs","repos_url":"https://api.github.com/users/speedplane/repos","events_url":"https://api.github.com/users/speedplane/events{/privacy}","received_events_url":"https://api.github.com/users/speedplane/received_events","type":"User","site_admin":false},"body":"Actually it looks like we're using Apache, not the MDL, so I'll switch it to that.","created_at":"2015-01-05T01:40:45Z","updated_at":"2015-01-05T01:40:45Z","html_url":"https://github.com/mozilla/pdf.js/pull/5545#discussion_r22445307","pull_request_url":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545","_links":{"self":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/comments/22445307"},"html":{"href":"https://github.com/mozilla/pdf.js/pull/5545#discussion_r22445307"},"pull_request":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545","id":26164305,"html_url":"https://github.com/mozilla/pdf.js/pull/5545","diff_url":"https://github.com/mozilla/pdf.js/pull/5545.diff","patch_url":"https://github.com/mozilla/pdf.js/pull/5545.patch","issue_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5545","number":5545,"state":"open","locked":false,"title":"Improved Text Selection By Padding Text Elements","user":{"login":"speedplane","id":671052,"avatar_url":"https://avatars.githubusercontent.com/u/671052?v=3","gravatar_id":"","url":"https://api.github.com/users/speedplane","html_url":"https://github.com/speedplane","followers_url":"https://api.github.com/users/speedplane/followers","following_url":"https://api.github.com/users/speedplane/following{/other_user}","gists_url":"https://api.github.com/users/speedplane/gists{/gist_id}","starred_url":"https://api.github.com/users/speedplane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/speedplane/subscriptions","organizations_url":"https://api.github.com/users/speedplane/orgs","repos_url":"https://api.github.com/users/speedplane/repos","events_url":"https://api.github.com/users/speedplane/events{/privacy}","received_events_url":"https://api.github.com/users/speedplane/received_events","type":"User","site_admin":false},"body":"## The Problem\r\nText selection in pdf.js does not work so well. If while dragging, your cursor is not directly on top of a text element, then you get unexpected results. This occurs with nearly all examples, including [the tracemonkey example](http://mozilla.github.io/pdf.js/web/viewer.html).  Try starting a selection, then dragging the mouse to a blank whitespace area beneath the initial selection. You'll see the selection gets reversed. If you keep moving your mouse, it flickers and is generally a horrible experience. I'm not the first to report this, it is the subject of at least #4629 and #4843. \r\n\r\n## The Solution\r\nThe reason why selection doesn't work is because most browsers rely on padding between text to detect text flow.  The solution, therefore, is to increase padding of each text element so that each element runs right up next to the next element. \r\n\r\n### Other Solutions\r\nAdding padding to each text element was recognized as a possible solution by @mitar in #4843.  However, in #4843, the suggested solution was relatively complex, which included modifying the padding dynamically whenever a mouse moves. It was also written in CoffeeScript for a completely separate viewer and porting it seemed difficult.\r\n\r\n### This Solution\r\nIn this solution, the padding is calculated when the text elements are added. For each added text element, we find the nearest neighbor to the right that is on the same line. We then set the `padding-right` of the text element to that distance.  Similarly, for `padding-bottom` we find the next line that is underneath the text element, and set the padding to the difference between lines.  Setting `padding-bottom` is especially helpful for PDFs that are double spaced (lots of space between lines).\r\n\r\nThe solution isn't all milk and honey though. The computation is `O(N^2)`, which could be bad for complex PDFs.  There are [fancier algorithms to find the nearest neighbor](http://en.wikipedia.org/wiki/Nearest_neighbor_search), but for now, for each text element, we look at every other text element to see if it's nearest.\r\n\r\n*UPDATE*: As discussed below, the `O(N^2)` issue in this pull request has been resolved by using a quadtree datastructure.","created_at":"2014-12-16T17:32:05Z","updated_at":"2015-01-05T01:40:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3a85c5dbe0f3136a780a377ecf4bc396a586df0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545/commits","review_comments_url":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545/comments","review_comment_url":"https://api.github.com/repos/mozilla/pdf.js/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5545/comments","statuses_url":"https://api.github.com/repos/mozilla/pdf.js/statuses/34b577d32d300de6c84a92eb1674c7e0d48e343b","head":{"label":"speedplane:padd-text-for-selection","ref":"padd-text-for-selection","sha":"34b577d32d300de6c84a92eb1674c7e0d48e343b","user":{"login":"speedplane","id":671052,"avatar_url":"https://avatars.githubusercontent.com/u/671052?v=3","gravatar_id":"","url":"https://api.github.com/users/speedplane","html_url":"https://github.com/speedplane","followers_url":"https://api.github.com/users/speedplane/followers","following_url":"https://api.github.com/users/speedplane/following{/other_user}","gists_url":"https://api.github.com/users/speedplane/gists{/gist_id}","starred_url":"https://api.github.com/users/speedplane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/speedplane/subscriptions","organizations_url":"https://api.github.com/users/speedplane/orgs","repos_url":"https://api.github.com/users/speedplane/repos","events_url":"https://api.github.com/users/speedplane/events{/privacy}","received_events_url":"https://api.github.com/users/speedplane/received_events","type":"User","site_admin":false},"repo":{"id":27348328,"name":"pdf.js","full_name":"speedplane/pdf.js","owner":{"login":"speedplane","id":671052,"avatar_url":"https://avatars.githubusercontent.com/u/671052?v=3","gravatar_id":"","url":"https://api.github.com/users/speedplane","html_url":"https://github.com/speedplane","followers_url":"https://api.github.com/users/speedplane/followers","following_url":"https://api.github.com/users/speedplane/following{/other_user}","gists_url":"https://api.github.com/users/speedplane/gists{/gist_id}","starred_url":"https://api.github.com/users/speedplane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/speedplane/subscriptions","organizations_url":"https://api.github.com/users/speedplane/orgs","repos_url":"https://api.github.com/users/speedplane/repos","events_url":"https://api.github.com/users/speedplane/events{/privacy}","received_events_url":"https://api.github.com/users/speedplane/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/speedplane/pdf.js","description":"PDF Reader in JavaScript","fork":true,"url":"https://api.github.com/repos/speedplane/pdf.js","forks_url":"https://api.github.com/repos/speedplane/pdf.js/forks","keys_url":"https://api.github.com/repos/speedplane/pdf.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/speedplane/pdf.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/speedplane/pdf.js/teams","hooks_url":"https://api.github.com/repos/speedplane/pdf.js/hooks","issue_events_url":"https://api.github.com/repos/speedplane/pdf.js/issues/events{/number}","events_url":"https://api.github.com/repos/speedplane/pdf.js/events","assignees_url":"https://api.github.com/repos/speedplane/pdf.js/assignees{/user}","branches_url":"https://api.github.com/repos/speedplane/pdf.js/branches{/branch}","tags_url":"https://api.github.com/repos/speedplane/pdf.js/tags","blobs_url":"https://api.github.com/repos/speedplane/pdf.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/speedplane/pdf.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/speedplane/pdf.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/speedplane/pdf.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/speedplane/pdf.js/statuses/{sha}","languages_url":"https://api.github.com/repos/speedplane/pdf.js/languages","stargazers_url":"https://api.github.com/repos/speedplane/pdf.js/stargazers","contributors_url":"https://api.github.com/repos/speedplane/pdf.js/contributors","subscribers_url":"https://api.github.com/repos/speedplane/pdf.js/subscribers","subscription_url":"https://api.github.com/repos/speedplane/pdf.js/subscription","commits_url":"https://api.github.com/repos/speedplane/pdf.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/speedplane/pdf.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/speedplane/pdf.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/speedplane/pdf.js/issues/comments/{number}","contents_url":"https://api.github.com/repos/speedplane/pdf.js/contents/{+path}","compare_url":"https://api.github.com/repos/speedplane/pdf.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/speedplane/pdf.js/merges","archive_url":"https://api.github.com/repos/speedplane/pdf.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/speedplane/pdf.js/downloads","issues_url":"https://api.github.com/repos/speedplane/pdf.js/issues{/number}","pulls_url":"https://api.github.com/repos/speedplane/pdf.js/pulls{/number}","milestones_url":"https://api.github.com/repos/speedplane/pdf.js/milestones{/number}","notifications_url":"https://api.github.com/repos/speedplane/pdf.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/speedplane/pdf.js/labels{/name}","releases_url":"https://api.github.com/repos/speedplane/pdf.js/releases{/id}","created_at":"2014-11-30T20:06:50Z","updated_at":"2014-12-25T01:18:20Z","pushed_at":"2015-01-04T17:07:26Z","git_url":"git://github.com/speedplane/pdf.js.git","ssh_url":"git@github.com:speedplane/pdf.js.git","clone_url":"https://github.com/speedplane/pdf.js.git","svn_url":"https://github.com/speedplane/pdf.js","homepage":"","size":39725,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"997096f40d03cc0e46458df0e596cba6f26e82ef","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1663468,"name":"pdf.js","full_name":"mozilla/pdf.js","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/pdf.js","description":"PDF Reader in JavaScript","fork":false,"url":"https://api.github.com/repos/mozilla/pdf.js","forks_url":"https://api.github.com/repos/mozilla/pdf.js/forks","keys_url":"https://api.github.com/repos/mozilla/pdf.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/pdf.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/pdf.js/teams","hooks_url":"https://api.github.com/repos/mozilla/pdf.js/hooks","issue_events_url":"https://api.github.com/repos/mozilla/pdf.js/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/pdf.js/events","assignees_url":"https://api.github.com/repos/mozilla/pdf.js/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/pdf.js/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/pdf.js/tags","blobs_url":"https://api.github.com/repos/mozilla/pdf.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/pdf.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/pdf.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/pdf.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/pdf.js/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/pdf.js/languages","stargazers_url":"https://api.github.com/repos/mozilla/pdf.js/stargazers","contributors_url":"https://api.github.com/repos/mozilla/pdf.js/contributors","subscribers_url":"https://api.github.com/repos/mozilla/pdf.js/subscribers","subscription_url":"https://api.github.com/repos/mozilla/pdf.js/subscription","commits_url":"https://api.github.com/repos/mozilla/pdf.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/pdf.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/pdf.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/pdf.js/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla/pdf.js/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/pdf.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/pdf.js/merges","archive_url":"https://api.github.com/repos/mozilla/pdf.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/pdf.js/downloads","issues_url":"https://api.github.com/repos/mozilla/pdf.js/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/pdf.js/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/pdf.js/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/pdf.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/pdf.js/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/pdf.js/releases{/id}","created_at":"2011-04-26T06:32:03Z","updated_at":"2015-01-04T23:51:30Z","pushed_at":"2015-01-03T19:40:15Z","git_url":"git://github.com/mozilla/pdf.js.git","ssh_url":"git@github.com:mozilla/pdf.js.git","clone_url":"https://github.com/mozilla/pdf.js.git","svn_url":"https://github.com/mozilla/pdf.js","homepage":"","size":104948,"stargazers_count":10196,"watchers_count":10196,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2295,"mirror_url":null,"open_issues_count":469,"forks":2295,"open_issues":469,"watchers":10196,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545"},"html":{"href":"https://github.com/mozilla/pdf.js/pull/5545"},"issue":{"href":"https://api.github.com/repos/mozilla/pdf.js/issues/5545"},"comments":{"href":"https://api.github.com/repos/mozilla/pdf.js/issues/5545/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla/pdf.js/pulls/5545/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/pdf.js/statuses/34b577d32d300de6c84a92eb1674c7e0d48e343b"}}}}