Skip to content

TextEditorDecoration applied to incorrect range if racing with user edits #74094

@Colengms

Description

@Colengms

Version: 1.33.1 (user setup)
Commit: 51b0b28
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.18362

The wrong text gets decorated if the user is typing when the decoration is applied.

Steps to Reproduce:

  1. Add the following to a didChangeTextDocument handler in an extension:
        let decoration: vscode.TextEditorDecorationType = vscode.window.createTextEditorDecorationType({
            color: "#FF00FF"
        });
        let txt1: string = textDocumentChangeEvent.document.getText();
        let editors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => e.document.uri === textDocumentChangeEvent.document.uri);
        for (let e of editors) {
            e.setDecorations(decoration, [new vscode.Range(1, 1, 1,10)]);
        }
        let txt2: string = textDocumentChangeEvent.document.getText();
  1. Prepare a file with some text i.e.:
XXXXXXXXXXXX
XXXXXXXXXXXX
  1. Put a breakpoint immediately after the first call to getText().
  2. When you hit that breakpoint, inspect txt1. You will see the contents of the file.
  3. While remaining at the breakpoint, paste a couple lines to the start of the file. For example, to make the file look like so:
YYYYYYYYYYYY
YYYYYYYYYYYY
XXXXXXXXXXXX
XXXXXXXXXXXX
  1. Step past the second call to getText(). You will see it retains the original content. This is good (better then changing the state of the document out from under us, before delivering didChangeTextDocument with the new edits). The intention here is to set a decoration within the second line of X's, and the apparent state of the document seems to imply this is what to expect.
  2. Continue, allowing the didChangeTextDocument handler to return.

Seeing: The decoration is applied to the wrong text.

Capture

Expected: The decoration range(s) should get adjusted based on the pending edits.

Metadata

Metadata

Assignees

Labels

editor-coreEditor basic functionalityfeature-requestRequest for new features or functionalitysemantic-tokensSemantic tokens issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions