vscode: Bug (?): auto-trim of trailing whitespace on the cursor line
With the “Trim Trailing Whitespace” (files.trimTrailingWhitespace
) option enabled, trailing whitespace is removed even on the cursor line (see below). I consider this to be a bug because in #24601 @alexdima indicated that the intended behavior is for trailing spaces to not be deleted in the cursor line. And also, current behavior is quite annoying and to my knowledge, other editors keep the line under cursor intact in similar situations.
Examples of where this behavior is really annoying:
- I finished writing a portion of the code, hit enter to get to the next line to continue on to the next portion (at this moment, the cursor is at correct indentation), and decide to save at this point. Cursor is then flung back to the beginning of the line and I have to hit tab several times to get back to my indentation.
- I start creating a variable and type
int
, then pause to think of a variable name, instinctively hit cmd+s, my space disappears.
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.79.1 (
4cb974a7aed77a74c7813bdccd99ee0d04901215
) - OS Version: macOS Ventura 13.4 (22F66)
Steps to Reproduce:
- Create/open any file
- Enter several trailing spaces in any line and leave the cursor where it is
- Hit Save: the trailing spaces will be removed
Expected behavior: the trailing spaces under the cursor remain and the “save” action does not move the cursor.
It would probably be the least invasive if a) this is an option (aka a second checkbox “Leave the cursor line as-is” b) it may be ok to delete trailing whitespace (i.e., keep the current behavior) if the cursor is on the line but not adjacent to the trailing whitespace. I would say that the rule of thumb here should be: save function should not move the cursor.
The main point is that saving should not move the cursor and it should not affect or remove things that were just typed.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 25
- Comments: 20 (1 by maintainers)
This issue still occurs in the newer VSCode versions: