Community
Participate
Working Groups
Current behavior of Ctrl-Shift-F with no selection is somewhat dangerous. If user hits Shift+Ctrl+F accidentally, for example by trying to search for references (Shift+Ctrl+G), the entire file is reformatted. In some cases the visible part of the file may not change and the user may continue to work being completely unaware of what happened. When the user later discovers effects of the accidental reformatting, it is already too late to use Undo since it would erase important changes made after the accident. The problem can be remedied by introducing a preference for formatting without selection. The possible values for the preference are: 1. Format the entire file (current behavior) 2. Format the current statement 3. Do nothing (not sure if this option makes sense) A similar feature request for JDT is in bug 419183.
Perhaps asking a confirmation when the entire file is to be formatted could be a better solution?
(In reply to Andrew Gvozdev from comment #1) > Perhaps asking a confirmation when the entire file is to be formatted could > be a better solution? I prefer the original proposal for two reasons: 1. Ability to format the current statement without having to select it is convenient. 2. Formatting the entire file takes two keystrokes - Ctrl+A, Shift+Ctrl+F. This is the same number of keystrokes as with a confirmation, but doesn't require user to wait for the dialog to appear before hitting the second keystroke.
The dialog could provide an option "Do not ask again" which could be backed by the preference you are suggesting.
(In reply to Andrew Gvozdev from comment #3) > The dialog could provide an option "Do not ask again" which could be backed > by the preference you are suggesting. Andrew, your proposal has been endorsed by Dani Megert in bug 419183 comment 10. I'll work on it.
(In reply to Sergey Prigogin from comment #4) > (In reply to Andrew Gvozdev from comment #3) > > The dialog could provide an option "Do not ask again" which could be backed > > by the preference you are suggesting. > > Andrew, your proposal has been endorsed by Dani Megert in bug 419183 comment > 10. I'll work on it. Note that you will need to have two separate don't ask dialogs: one for the empty selection and one for the entire selection. Otherwise, users can't decide to say yes to one case and no to the other. Would be great if you could also provide the same fix for JDT.
(In reply to Dani Megert from comment #5) > Note that you will need to have two separate don't ask dialogs: one for the > empty selection and one for the entire selection. Otherwise, users can't > decide to say yes to one case and no to the other. Selection of the entire file should be treated as any other non-empty selection and should not trigger a confirmation dialog.
(In reply to Sergey Prigogin from comment #6) > (In reply to Dani Megert from comment #5) > > Note that you will need to have two separate don't ask dialogs: one for the > > empty selection and one for the entire selection. Otherwise, users can't > > decide to say yes to one case and no to the other. > > Selection of the entire file should be treated as any other non-empty > selection and should not trigger a confirmation dialog. What's the difference then between having entire or no selection? In both cases you can accidentally format, and that's what you seem to be concerned about.
(In reply to Dani Megert from comment #7) > What's the difference then between having entire or no selection? In both > cases you can accidentally format, and that's what you seem to be concerned > about. I look at differently. The Format command operates on selection. Empty selection is a special case since it is treated as if the entire file was selected. It is logical to interpret the empty selection differently giving user a choice of the interpretation.
(In reply to Sergey Prigogin from comment #8) > (In reply to Dani Megert from comment #7) > > What's the difference then between having entire or no selection? In both > > cases you can accidentally format, and that's what you seem to be concerned > > about. > > I look at differently. The Format command operates on selection. Empty > selection is a special case since it is treated as if the entire file was > selected. It is logical to interpret the empty selection differently giving > user a choice of the interpretation. I can buy the *accidental* argument, but then making a difference whether all or nothing is selected sounds a bit strange.
(In reply to Dani Megert from comment #9) > I can buy the *accidental* argument, but then making a difference whether > all or nothing is selected sounds a bit strange. If you look at the region subject to formatting as a function of the selection size, you can clearly see that the only discontinuity of this function is between selection of size 1 and an empty selection. Discontinuity is a special point by nature, so it is not strange that it deserves a special treatment.
Ping on this. I just had to waste two hours untangling an accidental reformatting of a 2000-line file from the changes I'd made, and this hasn't been the first time by a long shot. This behavior may be OK for solitary developers, but in any situation where you have to submit clean patches for changes, this behavior is incredibly annoying. Thanks for your consideration!
A proposed solution is in https://git.eclipse.org/r/#/c/31338/. It depends on the change in platform text https://git.eclipse.org/r/#/c/31337/.
(In reply to Dani Megert from comment #9) > (In reply to Sergey Prigogin from comment #8) > > (In reply to Dani Megert from comment #7) > > > What's the difference then between having entire or no selection? In both > > > cases you can accidentally format, and that's what you seem to be concerned > > > about. > > > > I look at differently. The Format command operates on selection. Empty > > selection is a special case since it is treated as if the entire file was > > selected. It is logical to interpret the empty selection differently giving > > user a choice of the interpretation. > > I can buy the *accidental* argument, but then making a difference whether > all or nothing is selected sounds a bit strange. The difference is that selecting the entire file contents requires you to _do_ something, and it's clear from the UI (every line being highlighted) that the next action will apply to the entire contents.
Fixed by commits http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=27f00a30d886dc781df348ea1cc8bd5f228c42ca and http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=08fd13ed9f55297f738363484912acd806b8cbde Although the functionality is available in CDT 8.6, it manifests itself only on Platform 4.5M3 or higher.
*** cdt git genie on behalf of Sergey Prigogin *** Bug 419399 - Preference for Format with no selection A minor fix in the preference page. [*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=08fd13ed9f55297f738363484912acd806b8cbde
Is this worth a mention in the N&N? https://wiki.eclipse.org/CDT/User/NewIn86
(In reply to Marc Khouzam from comment #16) > Is this worth a mention in the N&N? > https://wiki.eclipse.org/CDT/User/NewIn86 Since it requires Platform 4.5 that will be released in June, it makes sense to describe it in https://wiki.eclipse.org/CDT/User/NewIn87
(In reply to Sergey Prigogin from comment #17) > Since it requires Platform 4.5 that will be released in June, it makes sense > to describe it in https://wiki.eclipse.org/CDT/User/NewIn87 Good point. I've created the page for you. I figure it is easier to add it now when it is fresh in your mind and environment than later on. https://wiki.eclipse.org/CDT/User/NewIn87
(In reply to Marc Khouzam from comment #18) Thanks a lot!
(In reply to Marc Khouzam from comment #18) > Good point. > I've created the page for you. I figure it is easier to add it now when it > is fresh in your mind and environment than later on. > > https://wiki.eclipse.org/CDT/User/NewIn87 (In reply to Sergey Prigogin from comment #19) > (In reply to Marc Khouzam from comment #18) > Thanks a lot! Well, I created the page but didn't put an entry for this new change. So let me thank you in advance for putting that in :)
*** cdt git genie on behalf of Sergey Prigogin *** Bug 419399 - Preference for Format with no selection More robust implementation of region expansion. [*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=90e95ab4eb6c4aa06fd1b894255582964631e533
New Gerrit change created: https://git.eclipse.org/r/43181