This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
in this case: class Foo { | } if I press Save File shortcut (Cmd+S on Mac), file is saved, but cursor jumps to column 0 (zero) and tab (or spaces) that were before the cursor are removed.
See issue #13063.
Milo, please evaluate. Thanks
Yes, this is effect of issue 13063 that I'm aware of. I can fix it by not preserving the whitespace on the line with the caret. I wanted to see how much negatively will users perceive this first. I personally tend to save often but I've already get used to the new WS-removal behavior so I only save when I'm e.g. at an end of a line with the newly written code. It's sort of subconscious but it works for me. If I accidentally remove wanted WS I press TAB to correct indentation. If we decide to preserve WS on line with the caret upon save then that preserved WS should not IMHO get removed later automatically. Consider: 1) Add some new code to method A.a(): class A { void a() { // some code // some new code | } // many other methods void b() { } } 2) Save. WS before caret (marked with '|') gets preserved 3) Commit to version-control but keep the file open. (Note that the diff would contain the extra WS on line with caret) 4) Add new code to b(): class A { void a() { // some code // some new code } // many other methods void b() { // new code| } } 5) Save. Commit. The change would contain both new code in b() and removal of the extra WS left in A.a(). This would be strange IMHO. So the WS in A.a() would stay there forever which I personally don't like much. A possibility could be to have a three-state option for WS removal: a) None - no WS removed upon Save. b) Standard - preserve WS on line with caret. c) Aggressive - the current behavior.
For me personally is acceptable to see that extra removed WS in step 5) if I know that IDE is doing this cleanup. What is not acceptable, is that 'Save' action moves caret.
> For me personally is acceptable to see that extra removed WS in step 5) if I know that IDE is doing this cleanup. It won't make any change since if you close and reopen the file between 3) and 4) there won't even be any clue that the WS in a() could be removed. > What is not acceptable, is that 'Save' action moves caret. OK, I will make it to retain WS before the caret by default. We could support "virtual caret position" in the future (which would look like the caret is at a particular column but there would be no corresponding text underneath) but it's not very straightforward to implement such thing with the Swing text package APIs.
Fixed. http://hg.netbeans.org/main/rev/3fbfb023ed57
Integrated into 'main-golden', available in NB_Trunk_Production #285 build Changeset: http://hg.netbeans.org/main/rev/3fbfb023ed57 User: Miloslav Metelka <mmetelka@netbeans.org> Log: #137529 - Save file shortcut moves tabbed cursor to column 0.
*** Issue 138467 has been marked as a duplicate of this issue. ***
I can understand the original motivation for this fix but I think the implementation is not perfect. It now refuses to remove whitespace at the end of the line even if I made an edit _elsewhere_ on the line. E.g. ---%<--- original public void messyOriginlCode () { <<EOL>> ---%<--- saved public void messyOriginalCode<<CARET>>() { <<EOL>> ---%<--- I think the removal of final whitespace should be suppressed only if the file is saved with the caret at the end of the line.
*** Issue 139999 has been marked as a duplicate of this issue. ***