{"action":"created","comment":{"url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/comments/48037722","id":48037722,"diff_hunk":"@@ -0,0 +1,78 @@\n+package sh.calaba.instrumentationbackend.actions.text;\n+\n+import android.text.Editable;\n+import android.text.TextUtils;\n+import android.view.inputmethod.BaseInputConnection;\n+import android.view.inputmethod.InputConnection;\n+import sh.calaba.instrumentationbackend.InstrumentationBackend;\n+import sh.calaba.instrumentationbackend.Result;\n+import sh.calaba.instrumentationbackend.actions.Action;\n+\n+public class SetSelection implements Action {\n+\n+    private static final String USAGE = \"This action takes 2 arguments:\\n([int] start, [int] end)\";\n+\n+    @Override\n+    public Result execute(final String... args) {\n+        if (args.length != 2) {\n+            return Result.failedResult(USAGE);\n+        } \n+\n+        final InputConnection inputConnection = InfoMethodUtil.tryGetInputConnection();\n+\n+        if (inputConnection == null) {\n+            return Result.failedResult(\"Unable to set selection, no element has focus\");\n+        }\n+\n+        if (!(inputConnection instanceof BaseInputConnection)) {\n+            return Result.failedResult(\"Connection is not an instance of 'BaseInputConnection'\");\n+        }\n+\n+        final BaseInputConnection baseInputConnection = (BaseInputConnection) inputConnection;\n+\n+        final Editable editable = baseInputConnection.getEditable();\n+\n+        if (editable == null) {\n+            return Result.failedResult(\"Unable to set selection, not editable\");\n+        }\n+\n+        final int argFrom, argTo;\n+\n+        try {\n+            argFrom = Integer.parseInt(args[0]);\n+            argTo = Integer.parseInt(args[1]);\n+        } catch (NumberFormatException e) {\n+            return Result.failedResult(USAGE);\n+        }\n+\n+        InstrumentationBackend.solo.runOnMainSync(new Runnable() {\n+            @Override\n+            public void run() {\n+                // Find length of non-formatted text\n+                int textLength = InfoMethodUtil.getEditableTextLength(editable);\n+                int from, to;\n+\n+                if (argFrom < 0) {\n+                    from = textLength + argFrom + 1;\n+                } else {\n+                    from = argFrom;\n+                }\n+\n+                if (argTo < 0) {\n+                    to = textLength + argTo + 1;\n+                } else {\n+                    to = argTo;\n+                }\n+","path":"server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/SetSelection.java","position":66,"original_position":66,"commit_id":"d7dc574bf2738986d55a15a10872495cd1d2a3e2","original_commit_id":"d7dc574bf2738986d55a15a10872495cd1d2a3e2","user":{"login":"TobiasRoikjer","id":5135960,"avatar_url":"https://avatars.githubusercontent.com/u/5135960?v=3","gravatar_id":"","url":"https://api.github.com/users/TobiasRoikjer","html_url":"https://github.com/TobiasRoikjer","followers_url":"https://api.github.com/users/TobiasRoikjer/followers","following_url":"https://api.github.com/users/TobiasRoikjer/following{/other_user}","gists_url":"https://api.github.com/users/TobiasRoikjer/gists{/gist_id}","starred_url":"https://api.github.com/users/TobiasRoikjer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TobiasRoikjer/subscriptions","organizations_url":"https://api.github.com/users/TobiasRoikjer/orgs","repos_url":"https://api.github.com/users/TobiasRoikjer/repos","events_url":"https://api.github.com/users/TobiasRoikjer/events{/privacy}","received_events_url":"https://api.github.com/users/TobiasRoikjer/received_events","type":"User","site_admin":false},"body":"-1 does not just mean text end, it means the last element, -2 means the second to last element. This is the same as various other programming language conventions.","created_at":"2015-12-18T15:47:25Z","updated_at":"2015-12-18T15:47:25Z","html_url":"https://github.com/calabash/calabash-android-server/pull/10#discussion_r48037722","pull_request_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/comments/48037722"},"html":{"href":"https://github.com/calabash/calabash-android-server/pull/10#discussion_r48037722"},"pull_request":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10","id":54049222,"html_url":"https://github.com/calabash/calabash-android-server/pull/10","diff_url":"https://github.com/calabash/calabash-android-server/pull/10.diff","patch_url":"https://github.com/calabash/calabash-android-server/pull/10.patch","issue_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/10","number":10,"state":"open","locked":false,"title":"Feature/append text","user":{"login":"TobiasRoikjer","id":5135960,"avatar_url":"https://avatars.githubusercontent.com/u/5135960?v=3","gravatar_id":"","url":"https://api.github.com/users/TobiasRoikjer","html_url":"https://github.com/TobiasRoikjer","followers_url":"https://api.github.com/users/TobiasRoikjer/followers","following_url":"https://api.github.com/users/TobiasRoikjer/following{/other_user}","gists_url":"https://api.github.com/users/TobiasRoikjer/gists{/gist_id}","starred_url":"https://api.github.com/users/TobiasRoikjer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TobiasRoikjer/subscriptions","organizations_url":"https://api.github.com/users/TobiasRoikjer/orgs","repos_url":"https://api.github.com/users/TobiasRoikjer/repos","events_url":"https://api.github.com/users/TobiasRoikjer/events{/privacy}","received_events_url":"https://api.github.com/users/TobiasRoikjer/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-18T00:03:01Z","updated_at":"2015-12-18T15:47:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4a61e1d7b420f21efa8a6a633be55d2ea8dac637","assignee":{"login":"sapieneptus","id":3009852,"avatar_url":"https://avatars.githubusercontent.com/u/3009852?v=3","gravatar_id":"","url":"https://api.github.com/users/sapieneptus","html_url":"https://github.com/sapieneptus","followers_url":"https://api.github.com/users/sapieneptus/followers","following_url":"https://api.github.com/users/sapieneptus/following{/other_user}","gists_url":"https://api.github.com/users/sapieneptus/gists{/gist_id}","starred_url":"https://api.github.com/users/sapieneptus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sapieneptus/subscriptions","organizations_url":"https://api.github.com/users/sapieneptus/orgs","repos_url":"https://api.github.com/users/sapieneptus/repos","events_url":"https://api.github.com/users/sapieneptus/events{/privacy}","received_events_url":"https://api.github.com/users/sapieneptus/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10/commits","review_comments_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10/comments","review_comment_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/10/comments","statuses_url":"https://api.github.com/repos/calabash/calabash-android-server/statuses/d7dc574bf2738986d55a15a10872495cd1d2a3e2","head":{"label":"calabash:feature/append-text","ref":"feature/append-text","sha":"d7dc574bf2738986d55a15a10872495cd1d2a3e2","user":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"repo":{"id":47641198,"name":"calabash-android-server","full_name":"calabash/calabash-android-server","owner":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/calabash/calabash-android-server","description":"Automated Functional testing for Android based on cucumber http://calaba.sh ","fork":false,"url":"https://api.github.com/repos/calabash/calabash-android-server","forks_url":"https://api.github.com/repos/calabash/calabash-android-server/forks","keys_url":"https://api.github.com/repos/calabash/calabash-android-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/calabash/calabash-android-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/calabash/calabash-android-server/teams","hooks_url":"https://api.github.com/repos/calabash/calabash-android-server/hooks","issue_events_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/events{/number}","events_url":"https://api.github.com/repos/calabash/calabash-android-server/events","assignees_url":"https://api.github.com/repos/calabash/calabash-android-server/assignees{/user}","branches_url":"https://api.github.com/repos/calabash/calabash-android-server/branches{/branch}","tags_url":"https://api.github.com/repos/calabash/calabash-android-server/tags","blobs_url":"https://api.github.com/repos/calabash/calabash-android-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/calabash/calabash-android-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/calabash/calabash-android-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/calabash/calabash-android-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/calabash/calabash-android-server/statuses/{sha}","languages_url":"https://api.github.com/repos/calabash/calabash-android-server/languages","stargazers_url":"https://api.github.com/repos/calabash/calabash-android-server/stargazers","contributors_url":"https://api.github.com/repos/calabash/calabash-android-server/contributors","subscribers_url":"https://api.github.com/repos/calabash/calabash-android-server/subscribers","subscription_url":"https://api.github.com/repos/calabash/calabash-android-server/subscription","commits_url":"https://api.github.com/repos/calabash/calabash-android-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/calabash/calabash-android-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/calabash/calabash-android-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/calabash/calabash-android-server/contents/{+path}","compare_url":"https://api.github.com/repos/calabash/calabash-android-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/calabash/calabash-android-server/merges","archive_url":"https://api.github.com/repos/calabash/calabash-android-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/calabash/calabash-android-server/downloads","issues_url":"https://api.github.com/repos/calabash/calabash-android-server/issues{/number}","pulls_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls{/number}","milestones_url":"https://api.github.com/repos/calabash/calabash-android-server/milestones{/number}","notifications_url":"https://api.github.com/repos/calabash/calabash-android-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/calabash/calabash-android-server/labels{/name}","releases_url":"https://api.github.com/repos/calabash/calabash-android-server/releases{/id}","created_at":"2015-12-08T18:28:38Z","updated_at":"2015-12-08T20:25:12Z","pushed_at":"2015-12-18T00:03:01Z","git_url":"git://github.com/calabash/calabash-android-server.git","ssh_url":"git@github.com:calabash/calabash-android-server.git","clone_url":"https://github.com/calabash/calabash-android-server.git","svn_url":"https://github.com/calabash/calabash-android-server","homepage":"","size":21450,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"calabash:develop","ref":"develop","sha":"16fa879816a22976cf433add778041a07d43b3fd","user":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"repo":{"id":47641198,"name":"calabash-android-server","full_name":"calabash/calabash-android-server","owner":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/calabash/calabash-android-server","description":"Automated Functional testing for Android based on cucumber http://calaba.sh ","fork":false,"url":"https://api.github.com/repos/calabash/calabash-android-server","forks_url":"https://api.github.com/repos/calabash/calabash-android-server/forks","keys_url":"https://api.github.com/repos/calabash/calabash-android-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/calabash/calabash-android-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/calabash/calabash-android-server/teams","hooks_url":"https://api.github.com/repos/calabash/calabash-android-server/hooks","issue_events_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/events{/number}","events_url":"https://api.github.com/repos/calabash/calabash-android-server/events","assignees_url":"https://api.github.com/repos/calabash/calabash-android-server/assignees{/user}","branches_url":"https://api.github.com/repos/calabash/calabash-android-server/branches{/branch}","tags_url":"https://api.github.com/repos/calabash/calabash-android-server/tags","blobs_url":"https://api.github.com/repos/calabash/calabash-android-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/calabash/calabash-android-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/calabash/calabash-android-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/calabash/calabash-android-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/calabash/calabash-android-server/statuses/{sha}","languages_url":"https://api.github.com/repos/calabash/calabash-android-server/languages","stargazers_url":"https://api.github.com/repos/calabash/calabash-android-server/stargazers","contributors_url":"https://api.github.com/repos/calabash/calabash-android-server/contributors","subscribers_url":"https://api.github.com/repos/calabash/calabash-android-server/subscribers","subscription_url":"https://api.github.com/repos/calabash/calabash-android-server/subscription","commits_url":"https://api.github.com/repos/calabash/calabash-android-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/calabash/calabash-android-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/calabash/calabash-android-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/calabash/calabash-android-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/calabash/calabash-android-server/contents/{+path}","compare_url":"https://api.github.com/repos/calabash/calabash-android-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/calabash/calabash-android-server/merges","archive_url":"https://api.github.com/repos/calabash/calabash-android-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/calabash/calabash-android-server/downloads","issues_url":"https://api.github.com/repos/calabash/calabash-android-server/issues{/number}","pulls_url":"https://api.github.com/repos/calabash/calabash-android-server/pulls{/number}","milestones_url":"https://api.github.com/repos/calabash/calabash-android-server/milestones{/number}","notifications_url":"https://api.github.com/repos/calabash/calabash-android-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/calabash/calabash-android-server/labels{/name}","releases_url":"https://api.github.com/repos/calabash/calabash-android-server/releases{/id}","created_at":"2015-12-08T18:28:38Z","updated_at":"2015-12-08T20:25:12Z","pushed_at":"2015-12-18T00:03:01Z","git_url":"git://github.com/calabash/calabash-android-server.git","ssh_url":"git@github.com:calabash/calabash-android-server.git","clone_url":"https://github.com/calabash/calabash-android-server.git","svn_url":"https://github.com/calabash/calabash-android-server","homepage":"","size":21450,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10"},"html":{"href":"https://github.com/calabash/calabash-android-server/pull/10"},"issue":{"href":"https://api.github.com/repos/calabash/calabash-android-server/issues/10"},"comments":{"href":"https://api.github.com/repos/calabash/calabash-android-server/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/calabash/calabash-android-server/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/calabash/calabash-android-server/statuses/d7dc574bf2738986d55a15a10872495cd1d2a3e2"}}}}