Autosave messes with cursor position

To replicate:

(This is inconsistent but if you repeat these steps you should see it...)

File | New
Go down to the empty line in the loop() function.

Start:
Press tab, as if you were about to type something indented, all nice and neat.
Think for a second, so the autosave is triggered.
BUG: What I see is the cursor is returned to the start of the line, and the tab (or spaces) are gone.
If you don't see a bug, try hitting TAB again.
If this does not happen for you, try using the keyboard to select the inserted tab (ie Press HOME, then hold down SHIFT and hit END), delete it, then wait for autosave to kick in again.
Goto Start:

It's not 100% consistent, but after a couple of deletes and TABs I get the BUG happening.

Key action is waiting in between each key press, so the autosave kicks in, as it is the autosave that is messing with things.

Version: 2.0.0
Date: 2022-09-14T07:06:37.759Z
CLI Version: 0.27.1 [a900cfb2]

Copyright © 2022 Arduino SA

Please see here

2 Likes

Hi @aarondc. As @Willem43 pointed out already, this is a known bug in Arduino IDE (actually in the IDE framework it is built on).

There is no true fix at this time, but there is a simple workaround @Willem43 discovered. I'll provide instructions:

  1. Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
  2. Select the "Preferences: Open Settings (UI)" command from the menu.
  3. A "Preferences" tab will now open in the Arduino IDE. In the "Search Settings" field of that tab, type editor.trimAutoWhitespace
  4. Uncheck the checkbox next to " Remove trailing auto inserted whitespace."
  5. Click the X icon on the "Preferences" tab.

Please let me know if you have any questions or problems while following those instructions.

The reason this is considered a workaround rather than a true fix is that the "Remove trailing auto inserted whitespace" is generally a convenient feature. However, I think it is an effective workaround because you are trading the loss of a minor convenience feature in exchange for avoiding a bug that seriously harms the usability of the IDE. The Tools > Auto Format will take care of removing the trailing whitespace anyway.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.