Bug 310712 - Remove trailing spaces (on save) feature doesn't remove spaces before cursor in the current line
Summary: Remove trailing spaces (on save) feature doesn't remove spaces before cursor ...
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: part (show other bugs)
Version: Git
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 350615 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-11-26 14:25 UTC by Davorin Učakar
Modified: 2015-10-09 12:16 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: Frameworks 5.16 (Applications 15.12)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Davorin Učakar 2012-11-26 14:25:41 UTC
KDE 4.9.80 (KatePart 3.7?)

When setting "Remove trailing spaces" to either "On Modified Lines" or "In Entire Document", trailing spaces are not removed in the current line before the cursor position.

Reproducible: Always

Steps to Reproduce:
1. Set "Remove trailing spaces" to "In Entire Document"
2. Add a few spaces at the end of a line in some document.
3. Position cursor at the end of the line or somwhere inside trailing spaces.
4 . Press Ctrl+S
Actual Results:  
In the current line, only spaces in after the cursor are removed. For other lines, it works fine.
Comment 1 Dominik Haumann 2012-11-26 14:48:36 UTC
This is by design, see:
http://quickgit.kde.org/?p=kate.git&a=commit&h=cebe2e4c47655d4fdef27ad4a306b89dfbdf3302

> only remove trailing spaces after cursor 
> This commit is dedicated to Milian, since he seems to have a spasm 
> in his left hand, such that he presses CTRL+S all the time (this 
> disease seems to be very widespread). The story is like this: 
> If you remove trailing spaces on save (either of all or only of 
> modified lines), and the cursor position is in the trailing spaces, 
> then the cursor jumps to the last character. The workaround is 
> that only trailing spaces after the cursor position are removed. 
>
> This might leave trailing spaces in the saved document, so be 
> careful with your cursor navigation. 
>
> Be warned: All bug reports for this will be assigned to you.
Comment 2 Milian Wolff 2012-11-26 21:55:55 UTC
Exactly.
Comment 3 Davorin Učakar 2012-11-26 22:55:57 UTC
(I guess this "spasm" is just a joke for the habit of saving the document very often, right?)

I don't believe this behaviour is preferred by the majority of users, it's inconsistent with other editors, too. Some checkbox like "Exclude current line" may be added for the current behaviour.
Comment 4 Dominik Haumann 2012-11-27 08:04:36 UTC
Yes, it's a joke.

Having an option for such a simple thing sounds is imo over engineering. I'd prefer another workaround, if possible... the best solution would be to set the cursor position to an "invalid position" after the last character. but that's not possible currently.
Comment 5 Andrew Udvare 2013-02-26 18:58:30 UTC
Why is this not going to be fixed? This is very unusual behaviour. I was used to having the cursor move to the beginning of the line if the line is empty. I really dislike having to remember now to get to a blank line before saving.
Comment 6 Steve Pryde 2014-05-27 00:24:03 UTC
I can see 2 ways to resolve this:
1. Remove trailing spaces in the saved document on disk but not the active workspace.
OR
2. Add a checkbox to enable/disable the specific behaviour described above.

Either way 'WONTFIX' definitely seems like the wrong option here.
Comment 7 Dominik Haumann 2015-10-08 21:19:32 UTC
Removing the trailing spaces just on disk won't work. Why? Because then, the document contents is different than the one on disk. And Kate uses the swap file mechanism: if the the system or kate crashes, then on startup, Kate looks whether a swap file exists. If so, it loads the swap file and replicates all edit actions in there. And replicating the edit actions relies on a synced contents, i.e. documents contents same as the contents of the file on disk.

Changing the document contents behind Kate's back is therefore not a good idea and the very reason why it behaves this way right now.
Comment 8 Dominik Haumann 2015-10-08 21:20:15 UTC
*** Bug 350615 has been marked as a duplicate of this bug. ***
Comment 9 Dominik Haumann 2015-10-08 21:27:48 UTC
Git commit 9cf4f7a35d231774ce0a1f1c9def4f3272a5c845 by Dominik Haumann.
Committed on 08/10/2015 at 21:27.
Pushed by dhaumann into branch 'master'.

fix bug #310712: remove trailing spaces also on line with cursor

FIXED-IN: Frameworks 5.16 (Applications 15.12)
CHANGELOG: fix bug #310712: remove trailing spaces also on line with cursor

M  +1    -12   src/document/katedocument.cpp

http://commits.kde.org/ktexteditor/9cf4f7a35d231774ce0a1f1c9def4f3272a5c845
Comment 10 Christoph Cullmann 2015-10-09 11:58:23 UTC
I think that killed one unittest
see
https://build.kde.org/job/ktexteditor%20master%20stable-kf5-qt5/112/
Comment 11 Christoph Cullmann 2015-10-09 12:16:39 UTC
Git commit 7552ac73f55de0b383dd7904ad98eaf19dae0ae9 by Christoph Cullmann.
Committed on 09/10/2015 at 12:16.
Pushed by cullmann into branch 'master'.

fix unit tests
make unit tests resilent against trailing space stripping, better than turning it off for them

M  +1    -1    autotests/input/indent/pascal/label1/expected
M  +1    -0    autotests/input/indent/pascal/label1/input.js
M  +1    -1    autotests/input/indent/xml/opening1/expected
M  +1    -0    autotests/input/indent/xml/opening1/input.js
M  +1    -1    autotests/input/indent/xml/self_closing1/expected
M  +1    -0    autotests/input/indent/xml/self_closing1/input.js

http://commits.kde.org/ktexteditor/7552ac73f55de0b383dd7904ad98eaf19dae0ae9