Repository navigation
Simplify RStudio Addin - #208
Conversation
This reverts commit 2265bd2 since we can actually use modifyRange.
krlmlr
left a comment
There was a problem hiding this comment.
I love pull requests that remove code while keeping functionality ;-)
| text <- context$selection[[1]]$text | ||
| if (all(nchar(text) == 0)) stop("No code selected") | ||
| out <- style_text(text) | ||
| rstudioapi::modifyRange( |
There was a problem hiding this comment.
Can we extract a wrapper around modifyRange() and mock that wrapper?
There was a problem hiding this comment.
The problem is that rstudioapi assigns the document ID dynamically, and modifyRange() needs this ID to select the document to modify, so I think we can't mock. The approach would have been something like 3fac3a9.
I suggest we just leave it without testing for now.
There was a problem hiding this comment.
The problem is that when modifying the file with modifyRange() we need the document id of the file to modify, which we get with getActiveDocumentContext() when run interactively. However, I don't see a way to get id without running getActiveDocumentContext() and ids are assigned dynamically (which can be tested by simply opening a file and tet the active context of it, closing it and get the context again).
This reverts commit 3fac3a9.
dfa8383 to
5eab449
Compare
- Hotfix: utf8 should not be verbose (#245). - Allow styling of Rmd files(#233). - Remove duplicate @family (#244). - Fixing token insertion (#242). - Capitalize Addin titles (#241). - Explicit `NULL` creation to make styler compatible with R3.2.0 (#237). - Improve vignettes (#232). - Allow exclusion of files with `style_pkg()` and `style_dir()`. - Correct styling with long strings (#230). - Add tools for re-indenting tokens (#217). - Math token spacing (#221). - Remove outdated line and col information (#218). - Empty input for styling does not cause an error (#227, #228). - Tools to insert tokens + application on `if`-`else` clauses (#212). - Improve example in documentation (#222). - Fix spacing around in (#214). - Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204). - Disallow line break after ( for function calls (#210). - Preserve space between `!` and bang (#209). - Simplify RStudio Addin (#208, #211). - Indention based on square brackets (#207). - Add vignette on introducing styler (#203). - Indent function declaration without curly braces correctly (#202). - Fix indention in if-else statement (#200). - Sorting key (#196). - Use safe sequences (#197). - Fix space between two commas (#195). - Keep single-line pipes on one line (#74). - Remove tidyr and dplyr dependency (#182, #183, @jimhester). - Fix parsing inconsistency (#188). - Substitute create filler (#190). - Introducing class vertical (#189). - Adapt line break rules (#172). - Fix `R CMD check` (#185). - Force argument evaluation for proper error handling (#179). - Add nonstrict version of set_space_before_comment (#174). - Add installation instructions to README (#175). - Addin to style highlighted region (#143). - Improve spelling (#168). - Add coverage badge - Change badge from WIP to active - Add the number of files to message (#166). - Improve documentation (#164). - Add informative messages while styling files (#165). - More examples in help file (#161). - No line breaks after pipe if comment is next token (#160). - Fixing spacing around `!` (non-bang-bang) (#157). - Finalize function documentation (#154). - Review vignette (#158). - Update bang-bang rule (#156).
Replaces #205. Closes #178 by making use of rstudioapi::insertText(). Simplifies code greatly plus the Addin can now style unsaved files. No automated testing possible though since insertText() needs the document ID, which we cannot obtain when mocking.