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.

Bug 137529

Summary: Save file shortcut moves tabbed cursor to column 0
Product: editor Reporter: martin_adamek <martin_adamek>
Component: Formatting & IndentationAssignee: Miloslav Metelka <mmetelka>
Status: RESOLVED FIXED    
Severity: blocker CC: jglick
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 138951    
Bug Blocks: 13063    

Description martin_adamek 2008-06-18 07:51:39 UTC
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.
Comment 1 Jan Lahoda 2008-06-18 08:08:21 UTC
See issue #13063.
Comment 2 Jan Becicka 2008-06-18 12:31:43 UTC
Milo, please evaluate. Thanks
Comment 3 Miloslav Metelka 2008-06-18 14:32:55 UTC
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.
Comment 4 martin_adamek 2008-06-18 14:41:38 UTC
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.
Comment 5 Miloslav Metelka 2008-06-18 16:27:40 UTC
> 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.
Comment 6 Miloslav Metelka 2008-06-24 13:24:06 UTC
Fixed.

http://hg.netbeans.org/main/rev/3fbfb023ed57
Comment 7 Quality Engineering 2008-06-27 16:29:19 UTC
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.
Comment 8 Jiri Prox 2008-06-30 11:43:43 UTC
*** Issue 138467 has been marked as a duplicate of this issue. ***
Comment 9 Jesse Glick 2008-07-02 00:41:09 UTC
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.
Comment 10 Petr Dvorak 2008-07-16 17:00:11 UTC
*** Issue 139999 has been marked as a duplicate of this issue. ***