Sign in Join
Wiki copytemporary

AboutTrimTrailingSpaces: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: AboutTrimTrailingSpaces

OldNewLine
1+Lazarus original behaviour (0.9.24) was that pressing a space at the end (or past the end) of line would not insert this space, but simple move the caret.
2+
3+- Tabs:
4+
5+While this seems a good and easy approach in first, it brings up some problems. Press tab (assuming you work with real tabs, and do not substitute them with spaces) at the end of line. The caret would move the correct amount of positions, but the tab was lost (since no text was inserted). Pressing a none-whitespace char now, would fill the line with spaces. This problem would be most noticeable, if you are on an empty line, and wish to intend it with a tab. It was not possible.
6+
7+The minimum solution would be to just store the space/tab mix that brought you do the caret position, and use it to fill the line, if a none-whitespace was inserted. But ignore it totally for anything else (So the end key jumps to the last none-whitespaces).
8+
9+- Tabs and backspace:
10+
11+This again would be inconsistent. If the last key you pressed was a tab (and inserted a real tab, not spaces), and you press backspace, you expect to delete the whole tab, not just go one single position to the left. A tab at the end of the line, should be deleted the same way than a tab in the middle of the line. (otherwise you had half a tab in the memory, if a none whitespace was inserted) So now you need to use the remembered mix for backspace too. \> This is especially important, if your auto-indent copied tabs from the previous line, and you want to un-indent by one tab \<
12+
13+This differs from the original implementation where the editor never inserted the trailing whitespace, and *all* actions behaved as if they (the spaces) were not there. There are at least some actions that are more consistent, if there behaviour is based on the (temporarily) existence of those spaces.
14+
15+- Caret Left/Right
16+
17+Once you do this, the next question is, how caret left/right should behave. If "caret past EOL" is "off", then caret-right jumps to the next line, if pressed at EOL. If you type a few trailing spaces at the end of the line there are 2 possible behaviours for the sequence "caret-left" - "caret-right" 1) go one left, jump to the next line (as you are at the end of line). This is strange, because you went one left from the end of line, and still were at the end of line.... 2) go one left; and going one right behave as everywhere else in the code =\> you end up on the same location as before
18+
19+Yet bot are valid expected behaviours
20+
21+- End Key
22+
23+Having looked at all this, the behaviour of the end key, can probably depend on the Caret Left/Right. If caret-right can see the trailing space, then so should the end key. (Again there is the case where neither of them will see it) \> Of course the behaviour must be defined for both Normal, and smart end-key \<
24+
25+- -
26+
27+So trim trailing spaces must have a well defined behaviour for
28+
29+- - dealing with tabs
30+ - handling backspace inside the trailing whitespaces
31+ - handling caret left/right
32+ - handling end-key
33+
34+- -
35+
36+currently we have 4 modes:
37+
38+- - On leave line
39+ - On leave or Edit line
40+ - On any caret move or edit line
41+ - Position Only (looses tabs)
42+
43+I do not see a case for a "store whitespace, but use only for padding" mode. This would be remember the tabs, if a none-whitespace is inserted, but do not remember it for backspace, end and caret moves.
44+
45+[[IDE Window: Editor Options General Misc|See Ide Editorr Options Help for how to setup your IDE]]
46+
47+---
48+*From the Free Pascal wiki, page "AboutTrimTrailingSpaces", as it stood on 2013-09-21 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
49+Category: Proposals

Back to history