{"action":"created","comment":{"url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/comments/30023006","id":30023006,"diff_hunk":"@@ -403,27 +416,49 @@ var PaginatedChoiceState = ChoiceState.extend(function(self, name, opts) {\n         var n = self.options_per_page;\n         if (n !== null) return n;\n \n-        var chars = self._chars();\n         n = self.metadata.page_start;\n+        var chars = self._chars(n);\n+        var page_choices = 1;\n \n         while (n-- > 0) {\n-            chars -= self.format_choice(self.choices[n], n).length;\n-            if (chars < 0) break;\n+            chars -= self.format_choice(self.choices[n], page_choices).length;\n+            page_choices++;\n+\n+            if (chars < 0) {\n+                // check if previous choice is the first choice\n+                if (n-1 === -1) {\n+                    // check if first choice fits in 'Back' space\n+                    chars += self.format_choice(self.back, self.choices.length).length;\n+                    if (chars >= 0) {\n+                        n--;  // decr n if it fits\n+                    }\n+                }\n+                break;\n+            }\n         }\n \n         return self.metadata.page_start - n - 1;\n     };\n \n-    self._chars = function() {\n+    self._chars = function(n) {\n         // TODO this needs to be made less naive, it assumes that the last page\n         // needs space for a 'more' choice and that the first page needs space\n         // for a 'back' choice\n-        return self.characters_per_page - [\n-            self.format_choice(self.back, self.choices.length),\n-            self.format_choice(self.more, self.choices.length),\n-            self.question_text + '\\n']\n-            .join('')\n-            .length;\n+        if (n === -1) {\n+            return self.characters_per_page - [\n+                self.format_choice(self.more, self.choices.length),\n+                self.question_text + '\\n']\n+                .join('')\n+                .length;\n+        } else {\n+            return self.characters_per_page - [\n+                self.format_choice(self.back, self.choices.length),\n+                self.format_choice(self.more, self.choices.length),\n+                self.question_text + '\\n']\n+                .join('')\n+                .length;\n+        }","path":"lib/states/choices.js","position":107,"original_position":107,"commit_id":"86407a62c0a5d87957a21ffcfa565d19aae7d591","original_commit_id":"86407a62c0a5d87957a21ffcfa565d19aae7d591","user":{"login":"justinvdm","id":1731223,"avatar_url":"https://avatars.githubusercontent.com/u/1731223?v=3","gravatar_id":"","url":"https://api.github.com/users/justinvdm","html_url":"https://github.com/justinvdm","followers_url":"https://api.github.com/users/justinvdm/followers","following_url":"https://api.github.com/users/justinvdm/following{/other_user}","gists_url":"https://api.github.com/users/justinvdm/gists{/gist_id}","starred_url":"https://api.github.com/users/justinvdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinvdm/subscriptions","organizations_url":"https://api.github.com/users/justinvdm/orgs","repos_url":"https://api.github.com/users/justinvdm/repos","events_url":"https://api.github.com/users/justinvdm/events{/privacy}","received_events_url":"https://api.github.com/users/justinvdm/received_events","type":"User","site_admin":false},"body":"Don't we need to handle the last page too (and only take into account the 'back' choice, but not the 'more' choice)?","created_at":"2015-05-11T09:11:38Z","updated_at":"2015-05-11T09:11:38Z","html_url":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208#discussion_r30023006","pull_request_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208","_links":{"self":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/comments/30023006"},"html":{"href":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208#discussion_r30023006"},"pull_request":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208"}}},"pull_request":{"url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208","id":35100253,"html_url":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208","diff_url":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208.diff","patch_url":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208.patch","issue_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/208","number":208,"state":"open","locked":false,"title":"Less naive splitting for PaginatedChoiceState","user":{"login":"gsvr","id":3907663,"avatar_url":"https://avatars.githubusercontent.com/u/3907663?v=3","gravatar_id":"","url":"https://api.github.com/users/gsvr","html_url":"https://github.com/gsvr","followers_url":"https://api.github.com/users/gsvr/followers","following_url":"https://api.github.com/users/gsvr/following{/other_user}","gists_url":"https://api.github.com/users/gsvr/gists{/gist_id}","starred_url":"https://api.github.com/users/gsvr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsvr/subscriptions","organizations_url":"https://api.github.com/users/gsvr/orgs","repos_url":"https://api.github.com/users/gsvr/repos","events_url":"https://api.github.com/users/gsvr/events{/privacy}","received_events_url":"https://api.github.com/users/gsvr/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-11T06:16:02Z","updated_at":"2015-05-11T09:11:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d13ddafbfdbe61cbff98db5927f5f76595057b6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208/commits","review_comments_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208/comments","review_comment_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/208/comments","statuses_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/statuses/86407a62c0a5d87957a21ffcfa565d19aae7d591","head":{"label":"praekelt:feature/issue-208-less-naive-splitting-for-paginatedchoicestate","ref":"feature/issue-208-less-naive-splitting-for-paginatedchoicestate","sha":"86407a62c0a5d87957a21ffcfa565d19aae7d591","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":7109673,"name":"vumi-jssandbox-toolkit","full_name":"praekelt/vumi-jssandbox-toolkit","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/vumi-jssandbox-toolkit","description":"Vumi JavaScript Sandbox toolkit. ","fork":false,"url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit","forks_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/forks","keys_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/teams","hooks_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/hooks","issue_events_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/events","assignees_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/tags","blobs_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/languages","stargazers_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/stargazers","contributors_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/contributors","subscribers_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/subscribers","subscription_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/subscription","commits_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/merges","archive_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/downloads","issues_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/releases{/id}","created_at":"2012-12-11T10:12:11Z","updated_at":"2015-04-19T06:31:08Z","pushed_at":"2015-05-11T08:53:55Z","git_url":"git://github.com/praekelt/vumi-jssandbox-toolkit.git","ssh_url":"git@github.com:praekelt/vumi-jssandbox-toolkit.git","clone_url":"https://github.com/praekelt/vumi-jssandbox-toolkit.git","svn_url":"https://github.com/praekelt/vumi-jssandbox-toolkit","homepage":null,"size":5793,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":21,"forks":6,"open_issues":21,"watchers":6,"default_branch":"master"}},"base":{"label":"praekelt:develop","ref":"develop","sha":"d7c59926348cb384974cbe034c0b4eeb43915710","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":7109673,"name":"vumi-jssandbox-toolkit","full_name":"praekelt/vumi-jssandbox-toolkit","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/vumi-jssandbox-toolkit","description":"Vumi JavaScript Sandbox toolkit. ","fork":false,"url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit","forks_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/forks","keys_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/teams","hooks_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/hooks","issue_events_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/events","assignees_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/tags","blobs_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/languages","stargazers_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/stargazers","contributors_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/contributors","subscribers_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/subscribers","subscription_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/subscription","commits_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/merges","archive_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/downloads","issues_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/releases{/id}","created_at":"2012-12-11T10:12:11Z","updated_at":"2015-04-19T06:31:08Z","pushed_at":"2015-05-11T08:53:55Z","git_url":"git://github.com/praekelt/vumi-jssandbox-toolkit.git","ssh_url":"git@github.com:praekelt/vumi-jssandbox-toolkit.git","clone_url":"https://github.com/praekelt/vumi-jssandbox-toolkit.git","svn_url":"https://github.com/praekelt/vumi-jssandbox-toolkit","homepage":null,"size":5793,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":21,"forks":6,"open_issues":21,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208"},"html":{"href":"https://github.com/praekelt/vumi-jssandbox-toolkit/pull/208"},"issue":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/208"},"comments":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/issues/208/comments"},"review_comments":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208/comments"},"review_comment":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/pulls/208/commits"},"statuses":{"href":"https://api.github.com/repos/praekelt/vumi-jssandbox-toolkit/statuses/86407a62c0a5d87957a21ffcfa565d19aae7d591"}}}}