{"action":"created","issue":{"url":"https://api.github.com/repos/rstudio/rstudio/issues/532","labels_url":"https://api.github.com/repos/rstudio/rstudio/issues/532/labels{/name}","comments_url":"https://api.github.com/repos/rstudio/rstudio/issues/532/comments","events_url":"https://api.github.com/repos/rstudio/rstudio/issues/532/events","html_url":"https://github.com/rstudio/rstudio/pull/532","id":118701370,"number":532,"title":"API endpoints to support Shiny gadgets + other tools","user":{"login":"kevinushey","id":1976582,"avatar_url":"https://avatars.githubusercontent.com/u/1976582?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinushey","html_url":"https://github.com/kevinushey","followers_url":"https://api.github.com/users/kevinushey/followers","following_url":"https://api.github.com/users/kevinushey/following{/other_user}","gists_url":"https://api.github.com/users/kevinushey/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinushey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinushey/subscriptions","organizations_url":"https://api.github.com/users/kevinushey/orgs","repos_url":"https://api.github.com/users/kevinushey/repos","events_url":"https://api.github.com/users/kevinushey/events{/privacy}","received_events_url":"https://api.github.com/users/kevinushey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-24T20:58:09Z","updated_at":"2015-11-25T07:23:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rstudio/rstudio/pulls/532","html_url":"https://github.com/rstudio/rstudio/pull/532","diff_url":"https://github.com/rstudio/rstudio/pull/532.diff","patch_url":"https://github.com/rstudio/rstudio/pull/532.patch"},"body":"This PR will expose some new endpoints to be used by Shiny gadgets (and potentially other client packages) for interacting with the IDE (primarily, the console and the current document).\r\n\r\nA quick demo showing how this might used to perform a refactor (find and replace) within the current document:\r\n\r\n![refactor](https://cloud.githubusercontent.com/assets/1976582/11380364/6402eabc-92aa-11e5-8ce9-29b0297e0469.gif)\r\n\r\nThus far the new API features exposed are:\r\n\r\n- `getActiveDocumentContext()`\r\n- `replaceRanges(ranges, text)`\r\n- `replaceSelection(text)`\r\n- `sendToConsole(code, echo, execute, focus)`\r\n\r\n@jjallaire @jcheng5 any thoughts on other things we might want to expose or how we might tweak the interfaces?\r\n\r\nWe might want to take this and then work on the UI for displaying + locating Shiny gadgets in a separate PR.\r\n\r\n------\r\n\r\n## TODO\r\n\r\n- [ ] Handle multiple selections in `getActiveDocumentContext()`"},"comment":{"url":"https://api.github.com/repos/rstudio/rstudio/issues/comments/159524084","html_url":"https://github.com/rstudio/rstudio/pull/532#issuecomment-159524084","issue_url":"https://api.github.com/repos/rstudio/rstudio/issues/532","id":159524084,"user":{"login":"jcheng5","id":129551,"avatar_url":"https://avatars.githubusercontent.com/u/129551?v=3","gravatar_id":"","url":"https://api.github.com/users/jcheng5","html_url":"https://github.com/jcheng5","followers_url":"https://api.github.com/users/jcheng5/followers","following_url":"https://api.github.com/users/jcheng5/following{/other_user}","gists_url":"https://api.github.com/users/jcheng5/gists{/gist_id}","starred_url":"https://api.github.com/users/jcheng5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcheng5/subscriptions","organizations_url":"https://api.github.com/users/jcheng5/orgs","repos_url":"https://api.github.com/users/jcheng5/repos","events_url":"https://api.github.com/users/jcheng5/events{/privacy}","received_events_url":"https://api.github.com/users/jcheng5/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T07:23:57Z","updated_at":"2015-11-25T07:23:57Z","body":"This looks great so far!\r\n\r\nWould you consider having `replaceRanges(ranges, text)` and `replaceSelection(text)` each take an (optional?) `id` parameter that identifies the editor tab to be mutated? If a gadget (or other source-code-modifying function) takes a while to execute and the user changes source tabs (or focuses a source window) in between `getActiveDocumentContext()` and one of the replace operations, you could end up mangling the wrong document, unless you can explicitly say that you're trying to mutate the same document that `getActiveDocumentContext()` was telling you about."}}