Skip to content

Invalid file-resource version (mtime) calculation might cause the editor model to sync and trim whitespaces unnecessarily #12327

@kittaakos

Description

@kittaakos

Bug Description:

From time to time, the auto-save causes the editor to trim whitespace unnecessarily. Initially reported in arduino/arduino-ide#437, but I could reproduce the bug with TheiaBlueprint, Version 1.35.0 (1.35.0.98), using a JS file.

Steps to Reproduce:

Open Theia Blueprint and create a JS file with this or structurally similar content where <|> is the current position, auto-save is on:

function foo() {
    // indent<|>
}
  1. Press enter so the file after pressing the Enter key is the following and <|> is the expected cursor position:
function foo() {
    // indent
    <|>
}
  1. After pressing enter and the auto-save task, sometimes the cursor jumps back to the first column
  2. If you cannot reproduce it, delete the new line to have the initial state, and repeat step 1.
monaco-editor-model-sync.mp4

There is another way:

  1. You have to disable auto-save,
  2. Press enter to start a new line with the expected indentation, enable auto-save,
  3. The leading whitespace is removed, although it was not requested.
monaco-editor-sync.mp4

File resource receives the file change event here

Here, an invalid mtime is compared with the stat

return !!this.version && this.version.mtime >= stat.mtime;

Text model update is triggered with empty edits array

this.updateModel(() => StandaloneServices.get(IModelService).updateModel(this.model, value), {

But since editor.trimAutoWhitespace is true, the whitespaces will be trimmed in the textModel: https://github.com/microsoft/vscode/blob/c20740a3a29112acd9345a5e898bbfb8116c7e24/src/vs/editor/common/model/textModel.ts#L1331-L1334

Additional Information

  • Operating System: macOS
  • Theia Version: TheiaBlueprint, Version 1.35.0 (1.35.0.98)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions