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

Unnecessary code and decoration with :after prevents dnd #80666

Closed
usernamehw opened this issue Sep 10, 2019 · 7 comments · Fixed by #108379
Closed

Unnecessary code and decoration with :after prevents dnd #80666

usernamehw opened this issue Sep 10, 2019 · 7 comments · Fixed by #108379
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-drag-and-drop Editor UI drag-and-drop operations insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Milestone

Comments

@usernamehw
Copy link
Contributor

Issue Type: Bug

  1. Have unused variable in the first line of the file const asdf = 0; (any line tbh, just an example)
  2. Create decoration on the same line with the after property specified
const decorationType = vscode.window.createTextEditorDecorationType({
	isWholeLine: true,
});
const decorationOptions: vscode.DecorationOptions = {
	range: new vscode.Range(0, 0, 0, 0),
	renderOptions: {
		after: {
			contentText: 'random',
		},
	},
};
editor.setDecorations(decorationType, [decorationOptions]);
  1. Try to drag-n-drop text to that line

If I reference that variable (remove unused status) - then dnd works fine again.

VS Code version: Code - Insiders 1.39.0-insider (55825e9, 2019-09-10T05:25:22.729Z)
OS version: Windows_NT x64 10.0.18362

@alexdima
Copy link
Member

I can reproduce. I cannot drop on the line:

TO_UPLOAD

@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Oct 1, 2019
@rebornix
Copy link
Member

Weird bug. While mouseDownAndMove, the mouse event target is span <- span <- view line <- view lines <- .... However once it stops, the last cached mouse event target is span <- span <- view line <- null when dropping in above case. The mouse target somehow gets unconnected from view lines.

@alexdima
Copy link
Member

@rebornix That might happen because the line gets redrawn. In that case, the line becomes orphaned. I think the line might get redrawn due to inline decorations getting added/removed as drop feedback or as hover range feedback.

@KapitanOczywisty
Copy link
Contributor

@rebornix @alexdima Since this is pretty annoying bug when using Error Lens extension, I spend some time and found what exactly is wrong. Basically lines with after decorator are redrawn because lineDecorations has the same elements, but in different order. I'm pretty sure order is messed by DragAndDropController._onEditorMouseDrag combined with some other regular task, but this is not important for the actual fix.

Meanwhile event used for drop target is gathered when mouse is still on the move


and the render cycle passes before this event is used
const position = this._findMousePosition(this._lastMouseEvent!, true);


To fix this, lineDecorations have to be sorted here: (before condition here):

this.lineDecorations = lineDecorations;

Or this function has to ignore elements order

public static equalsArr(a: LineDecoration[], b: LineDecoration[]): boolean {
const aLen = a.length;
const bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i < aLen; i++) {
if (!LineDecoration._equals(a[i], b[i])) {
return false;
}
}
return true;
}

I've tested both options in DevTools and this fixes issue. Since this is rather crucial part of code I'll leave proper implementation to you.

@alexdima alexdima self-assigned this Sep 3, 2020
@alexdima alexdima added this to the September 2020 milestone Sep 3, 2020
@alexdima alexdima modified the milestones: September 2020, On Deck Oct 1, 2020
@rebornix rebornix added the help wanted Issues identified as good community contribution opportunities label Oct 12, 2020
@rebornix rebornix removed their assignment Nov 5, 2020
@alexdima alexdima modified the milestones: On Deck, November 2020 Nov 20, 2020
@alexdima alexdima removed the help wanted Issues identified as good community contribution opportunities label Nov 20, 2020
@alexdima
Copy link
Member

To verify:

  • package.json:
{
    "publisher": "alex",
    "name": "80666",
    "version": "1.0.0",
    "engines": {
        "vscode": "^1.0.0"
    },
    "main": "main.js",
    "activationEvents": ["*"]
}
  • main.js:

const vscode = require('vscode');

exports.activate = function() {
    const decorationType = vscode.window.createTextEditorDecorationType({
        isWholeLine: true,
    });
    const decorationOptions = {
        range: new vscode.Range(2, 1000, 2, 1000),
        renderOptions: {
            after: {
                contentText: 'random',
            },
        },
    };
    vscode.window.activeTextEditor.setDecorations(decorationType, [decorationOptions]);
}
  • file.ts:

function x() {
    const asdf = 0;
}

@alexdima alexdima added the author-verification-requested Issues potentially verifiable by issue author label Dec 1, 2020
@github-actions
Copy link

github-actions bot commented Dec 1, 2020

This bug has been fixed in to the latest release of VS Code Insiders!

@usernamehw, you can help us out by confirming things are working as expected in the latest Insiders release. If things look good, please leave a comment with the text /verified to let us know. If not, please ensure you're on version ac165d7 of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

@usernamehw
Copy link
Contributor Author

/verified Tested by using Error Lens extension decorations

@lszomoru lszomoru added verified Verification succeeded and removed z-author-verified labels Dec 4, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-drag-and-drop Editor UI drag-and-drop operations insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@rebornix @lszomoru @alexdima @usernamehw @KapitanOczywisty and others