Don't remove trailing whitespace from cursor line
AbandonedPublic

Authored by cullmann on Apr 17 2018, 8:40 AM.

Details

Reviewers
dhaumann
sraizada
Group Reviewers
KTextEditor
Summary

When the 'remove trailing whitespace' option is enabled, if and only if the cursor is at the end of a line with trailing whitespace, the cursor position will be held instead of deleting the whitespace its position depends upon. Other lines will still have trailing whitespace removed. Useful to not lose auto-indent for those who save often.

Diff Detail

Repository
R39 KTextEditor
Lint
Lint Skipped
Unit
Unit Tests Skipped
sraizada created this revision.Apr 17 2018, 8:40 AM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptApr 17 2018, 8:40 AM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
sraizada requested review of this revision.Apr 17 2018, 8:40 AM

Forgot to put this in the first submission: it fails test 66 vimode_keys, I believe this may be related to bug 392858 - vi mode :q (quit) command works in Kate but not KWrite https://bugs.kde.org/show_bug.cgi?id=392858
Every other test passes.

anthonyfieroni added a subscriber: anthonyfieroni.EditedApr 17 2018, 8:48 AM

But if you do this

do_work(); |

will not remove trailling space after ';' before corsor. You should explicit check that you have only whitespace on the line regardless of position.

Would it be appropriate to add this as a config option in the settings? Because to me, keeping the sort of whitespace you describe seems like the better behavior:
doSomething(a, b, |
^ is correct. But obviously there are differing opinions on this, and a setting would resolve that.

The behavior that is proposed here was like Kate behaved before, and as result we got bug reports that not all trailing spaces were removed. So we removed this.

I can see that when saving very often, this may be annoying. On the other hand, the current behavior is very deterministic: Remove trailing spaces definitely should remove ALL trailing spaces without any exceptions.

As such: -2 for this patch - sorry, but we are turning in circles otherwise, changing behavior forth and back and forth and back.

A config option would work, but I am against it, since in my opinion this option belongs to a category that just bloat up our already complex config dialogs.

A by far better fix would be to allow the cursor to be placed behind the last text column:

 do_work(); |
<--------->

Note, the length of the line does not include the space after saving, still the cursor keeps its position.

But here comes the challenge: Currently, Kate does not allow the cursor to be positioned behind the last valid cursor position in normal editing mode. It does work in block-selection mode, though.
So the real / true fix would be much better, but will also be much harder.

But with that background in mind, I do not think we should add poor workarounds that do not fix the real problem, sorry. So I'd reject this patch, and vote with -1 against an option, and with +1 to a proper fix that would allow the cursor position in this case to be behind the last column.

@sraizada I am just seeing that this is your first KDE patch, nice! I hope that you do not get discouraged by my comments, I am just trying to find good solutions that work for everyone, and in this case, the solution this patch proposed did not work out in the past...

dhaumann requested changes to this revision.Jun 9 2018, 9:55 AM

See arguments above: If we change it, another one will come over time and submit yet another patch to revert again, and again. This patch cannot go in as is.

This revision now requires changes to proceed.Jun 9 2018, 9:55 AM
Restricted Application edited subscribers, added: kde-frameworks-devel, kwrite-devel; removed: Frameworks. · View Herald TranscriptJun 9 2018, 9:55 AM
cullmann requested changes to this revision.Jul 14 2018, 5:30 PM
cullmann added a subscriber: cullmann.

> I agree that the current state is ok and we arrived there after X iterations. I can agree that it might be bad for people with the habit to save each 5 seconds, but actually, given we have swap files for crash recovery, there is no reason to do so.

cullmann commandeered this revision.Jul 15 2018, 5:16 PM
cullmann abandoned this revision.
cullmann edited reviewers, added: sraizada; removed: cullmann.

> as said, we don't want that behavior change, sorry for that.