Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor randomly jumps to beginning of line #437

Closed
3 tasks done
tomotvos opened this issue Jul 6, 2021 · 15 comments · Fixed by #1972
Closed
3 tasks done

Cursor randomly jumps to beginning of line #437

tomotvos opened this issue Jul 6, 2021 · 15 comments · Fixed by #1972
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@tomotvos
Copy link

tomotvos commented Jul 6, 2021

Describe the problem

While editing, the cursor sometimes randomly jumps to the beginning of a new line

To reproduce

  1. Edit sketch
  2. Usually when typing a new line, cursor will jump to beginning of next line
  3. Seems to be related to auto-indent with tabs

Expected behavior

The cursor should not jump around and stay where I am typing

Arduino IDE version

2.0.0-beta.7

Operating system

macOS

Operating system version

Big Sur

Additional context

Additional reports

Workaround

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

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@ubidefeo
Copy link

ubidefeo commented Jul 7, 2021

@tomotvos
this is a bug we have experienced but had not made it into the backlog yet, so thank you for reporting it.
It is caused by the Language Server pre-processing which we'll get to in the future to make it less prone to interfere with the user's cursor. After all getting the cursor stolen from you as you type is not something anyone can like 👍🏼

@cmaglie cmaglie removed the type: bug label Sep 16, 2021
@rsora rsora added the type: imperfection Perceived defect in any part of project label Sep 22, 2021
@per1234
Copy link
Contributor

per1234 commented Oct 24, 2021

There is a nice screencast demonstrating the bug in the other report we received: #476 (comment)

@per1234 per1234 added the topic: code Related to content of the project itself label Oct 24, 2021
@gdarthy
Copy link

gdarthy commented Nov 7, 2021

It happens everytime you are on new line, then press TAB, cursor jumps back to home position of line, then, when you type anything, it jumps one line below. It's very annoying, I don't understand why this is not fixed yet since it makes working with IDE v2 frustrating. Considering going back to 1.8.

Bug still on IDE 2.0.0-beta.12 on Windows 10

@ubidefeo
Copy link

ubidefeo commented Nov 7, 2021

@gdarthy this bug is due to a faulty interaction between the editor and the Language Server.
We're rewriting the LS to address a lot of these bugs.
We understand the frustration, it bothers us as much as it bothers you :)

The team is hard at work to release a stable IDE 2.0

Thank you for your comment.
Ubi

@MArimont3
Copy link

IDE 2.0 rc3 (Windows 10) : cursor jumps after hitting enter -> jumps to new line, removes spaces before previous line, breaks words, inserts spaces, ...
Very weird behavior.
I am using the IDE since end of dec. Seems to get worse and worse. Becomes nearly unusable...

@ubidefeo
Copy link

@cmaglie @per1234
can we close this one?

@cmaglie
Copy link
Member

cmaglie commented Jul 29, 2022

can we close this one?

No, it's still happening with the current nightly:

Version: 2.0.0-rc9-nightly-20220729
Date: 2022-07-29T03:40:20.747Z
CLI Version: 0.25.0 [4fd95834]

@Willem43T
Copy link

I am experiencing this with the latest nightly. I did not have this before, only with the latest few nightlys.

Version: 2.0.0-rc9.1-nightly-20220810
Date: 2022-08-10T09:41:17.361Z
CLI Version: 0.0.0-git []

@per1234
Copy link
Contributor

per1234 commented Aug 20, 2022

I am able to reproduce this on my Linux machine, but not on my Windows machine.

@Willem43T did some investigation and shared their valuable findings on the Arduino Forum:

https://forum.arduino.cc/t/cursor-jumping-problem/1023535

I'll document what I have learned about the issue here:

To reproduce

  1. Select File > Preferences... from the Arduino IDE menus.
  2. Check the box next to "☐ Auto save".
    I use Auto save for this demo because it produces the more disruptive behavior as reported in the issue, but the bug occurs even on manual save when Auto Save is disabled.
  3. Click the OK button.
  4. Open the "Command Palette" via the Ctrl+Shift+P (Command+Shift+P for macOS users) keyboard shortcut.
  5. Select the "Preferences: Open Settings (UI)" command.
  6. In the "Search Settings" field, type editor.trimAutoWhitespace
  7. Check the checkbox next to "☐ Remove trailing auto inserted whitespace."
    This is the default, the instructions are only ensuring you don't have a custom setting.
  8. In the "Search Settings" field, type files.trimTrailingWhitespace
  9. Uncheck the checkbox next to " When enabled, will trim trailing whitespace when saving a file."
    This is the default, the instructions are only ensuring you don't have a custom setting.
  10. Create the following sketch code:
    void setup() {
      // indented line
    }
    void loop() {}
  11. Place the cursor at the end of line 2.
  12. Press Enter
    🙂 Whitespace is automatically inserted at the start of the new line to indent it to the same level as the previous one:
    image
  13. Wait for the Auto Save operation to complete, as indicated by the disappearance of the indicator from the right side of the sketch tab.

🐛 The whitespace is removed from line 2:

image

I set "editor.renderWhitespace": "all" for these screenshots in order to make the whitespace visible as a "•".

Expected behavior

In short: the VS Code behavior. This is the behavior the Arduino IDE has on my Windows machine.

I expect the Arduino IDE to work exactly like that, and to work that way consistently.

I'll provide the exact descriptions of the expected behavior of each of the related settings.

editor.trimAutoWhitespace

Default: true

Remove automatically inserted whitespace when it would end up as trailing whitespace.

This feature is completely unrelated to saving. Trimming is done on the fly while the user is editing, even when auto save is disabled.

  1. Open the "Command Palette" via the Ctrl+Shift+P (Command+Shift+P for macOS users) keyboard shortcut.
  2. Select the "Preferences: Open Settings (UI)" command.
  3. In the "Search Settings" field, type editor.trimAutoWhitespace
  4. Check the checkbox next to "☐ Remove trailing auto inserted whitespace."
  5. Create the following sketch code:
    void setup() {
      // indented line
    }
    void loop() {}
  6. Place the cursor at the end of line 2.
  7. Press Enter
    Whitespace is automatically inserted at the start of the new line to indent it to the same level as the previous one:
    image
  8. Press Enter

The automatically inserted whitespace on the previous line is removed:

image

files.trimTrailingWhitespace

Default: false

Remove all trailing whitespace on explicit save (when the user triggers a save via File > Save).

Whitespace is not trimmed on auto save.

  1. Select File > Preferences... from the Arduino IDE menus.

  2. Check the box next to "☐ Auto save".

  3. Click the OK button.

  4. Open the "Command Palette" via the Ctrl+Shift+P (Command+Shift+P for macOS users) keyboard shortcut.

  5. Select the "Preferences: Open Settings (UI)" command.

  6. In the "Search Settings" field, type files.trimTrailingWhitespace

  7. Check the checkbox next to "☐ When enabled, will trim trailing whitespace when saving a file."

  8. Create the following sketch code:

    void setup() {
      // indented line
    }
    void loop() {}
  9. Place the cursor at the end of line 2.

  10. Press Enter
    Whitespace is automatically inserted at the start of the new line to indent it to the same level as the previous one:
    image

  11. Wait for the Auto Save operation to complete, as indicated by the disappearance of the indicator from the right side of the sketch tab.
    The whitespace is not removed:
    image

  12. Select File > Save from the Arduino IDE menus.

All trailing whitespace is removed from the sketch:

image

Arduino IDE version

2.0.0-rc9.2.snapshot-de32bdd

Operating system

  • Ubuntu 20.04 (the machine where I can reproduce bug)
  • Windows 10 (the machine where I cannot reproduce bug)

Additional context

Since we have reports of this occurring on Linux, macOS, and Windows, I don't think the difference in operating systems between my two machines is the relevant factor.


I have all default Arduino IDE settings on both machines.


I am also able to reproduce the bug on my Linux machine using Theia Blueprint versions "0.25.0 (Beta)" (matching the version of Theia currently used by Arduino IDE) and "1.28.0 (Beta)" (the latest version).

I am not able to reproduce the bug on my Windows machine using Theia Blueprint.

This leads me to believe that the bug is in Eclipse Theia or one of its dependencies, not a bug in the Arduino IDE code base.


I found this similar issue in the Theia repository: eclipse-theia/theia#8718

However, that is related to the presence of an .editorconfig file. The bug occurs in sketches that do not contain such a file and I also don't have any in the parent folders. I also tried adding one to the sketch with trim_trailing_whitespace = false, and the bug still occurs. This leads me to believe that the bug is different from that described in eclipse-theia/theia#8718.


The fact that the issue occurs in Theia Blueprint, and that it occurs even after I run the "Arduino: Stop Language Server" command or when I have no board selected seems to be evidence against the previous hypothesis that this was related to the language server.


I am not able to reproduce the bug using VS Code with the same settings on my Linux machine.


As discovered by @Willem43T, the bug no longer occurs if editor.trimAutoWhitespace is set to false.

While the use of this workaround by those afflicted will mitigate the impact, I think the editor.trimAutoWhitespace feature is useful when working as intended and also provides parity with Arduino IDE 1.x, which has equivalent behavior. So I don't see globally changing the default value in the Arduino IDE code base as a viable solution for the bug.


The behavior of the bug does not match the behavior of files.trimTrailingWhitespace. Only the automatically inserted whitespace is removed. Any other trailing whitespace in the sketch is preserved.

@KurtE
Copy link

KurtE commented Aug 28, 2022

As I mentioned in 1364 this is one of a few bugs that would keep me from using IDE2 for any serious stuff.
The other main one is the functionality of the Serial Monitor.

Hope it gets fixed soon. Will try the workaround. But as mentioned I don't think that is the correct end solution, as I would still prefer the files to have trailing white space removed.

@Willem43T
Copy link

The cursor jump bug made the editor mostly unusable for me. With the workaround I can use IDE 2 which offers huge advantages for me and the way I work. I agree it is not ideal and definitely not the final solution. However, since the complier does not mind a few possible trailing spaces, neither do I (for the moment). I am sure it will eventually be solved.

The serial monitor is a different issue and not one that particularly effects me at present - I am sure it will also eventually be solved.

Considering the progress over the last few updates, the team is doing well - keep up the good work.

@KurtE
Copy link

KurtE commented Aug 29, 2022

@Willem43T - I totally agree, the work around, helped a lot. Keeps me from using another editor to make the changes. And I agree that for the most part, things keep getting better

Suggestion to Arduino:
How are users expected to even know there are additional preferences that can be changed?
That is:

Open the "Command Palette" via the Ctrl+Shift+P (Command+Shift+P for macOS users) keyboard shortcut.
Select the "Preferences: Open Settings (UI)" command.
In the "Search Settings" field, type editor.trimAutoWhitespace
Check the checkbox next to "☐ Remove trailing auto inserted whitespace."

Maybe a Menu item somewhere? Tools->Advanced->Command Palette

Maybe something at the end of the preferences dialog, like the Arduino 1:

More preferences can be edited directly in the file:'
c:\Users\kurte\appData\local\arduino15\preferences.txt
...

Where, maybe instead button that takes you to Command Palette or to the UI preferences page...

Serial Monitor - I use a lot, to help debug things as well as to document stuff. So, hopefully you are right, and they will fix the major issues with it soon.

@Willem43T
Copy link

Willem43T commented Aug 29, 2022

@KurtE - F1 will open the Advanced Preferences (same as Ctrl+Shift+P). In search enter "settings" and select "Open Settings (UI)" from the list.

Under "Editor" you now have hundreds of understandable as well as some really obscure settings. Quite a way down you will also find, under the "T"s (with Editor still highlighted on the left), the above "Trim Auto Whitespace". If you hover the cursor over the label it will show the editor.trimAutoWhitespace search text. I do not know where to get that from initially as a search.

Have fun.

kittaakos pushed a commit that referenced this issue Mar 21, 2023
before checking if it's in sync or not.

Closes #437

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit that referenced this issue Mar 21, 2023
before checking if it's in sync or not.

Closes #437

Signed-off-by: Akos Kitta <[email protected]>
@kittaakos
Copy link
Contributor

Hi, I have a proposed fix in #1972. Could somebody help with the verification? Here is the documentation on how to do the beta testing. Thank you!

@Willem43T
Copy link

Willem43T commented Mar 21, 2023

I downloaded the PR as a Windows 64 zip file and installed it. About lists it as

Version: 2.0.5-snapshot-baf98f0
Date: 2023-03-21T09:51:03.186Z
CLI Version: {3}

Copyright © 2023 Arduino SA

Next I loaded a sketch, enabled all the skip whitespace options, particularly the "trimAutoWhitespace" which provided the current work around.

Editing did not exhibit the, by now, well known cursor jumping randomly to the start of the line. I then closed the snapshot version, leaving the whitespace settings as is, and loaded my previous knightly. This immediately had the cursor jumping to the start problem. Back to the PR version and all seems to behave correctly.

kittaakos pushed a commit that referenced this issue Mar 28, 2023
before checking if it's in sync or not.

Closes #437

Signed-off-by: Akos Kitta <[email protected]>
@kittaakos kittaakos added the conclusion: resolved Issue was resolved label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants