Closed yixiang closed 8 years ago
No it is not exactly the same, see the first line, the early return condition is exactly the opposite of formatSelectedCharacters.
So formatSelectCharacters works when a range of character is selected, and formatCurrentStatement works when there is no characters selected.
An alternatively approach could be removing the following lines from formatSelectedCharacters.
if (![TRVSXcode textViewHasSelection]) return;
But then we need to advertise the fact that it work with and WITHOUT characters selected, and explain what it does when there is no characters selected.
This feature seems too simple to be useful, but I've been testing this feature myself for very long time. It's really handy for users who can't do file-level auto-formatting but want to keep newly added code formatted as they edit.
what are the selectedRanges when there is no selection?
Its location is cursor position and length is zero. On Wed, Oct 7, 2015 at 01:18 Travis Jeffery notifications@github.com wrote:
what is the selectedRange when there is no selected range?
— Reply to this email directly or view it on GitHub https://github.com/travisjeffery/ClangFormat-Xcode/pull/102#issuecomment-146110967 .
this is literally exactly the same as formatSelectedCharacters: https://github.com/yixiang/ClangFormat-Xcode/blob/ae4b492be7b59f44fb939ec124a4a20d8869cbe3/ClangFormat/TRVSFormatter.m#L52-L69