Emmet - Fixing bug in toggle comment with multi cursor (#42857)

* Fixing issue with toggleComment on multiple nested cursors

* Fix error when an edit is empty

* reordering

* adding a test for toggleComment on nested selections

* Adding test for stylesheet files

* Removing change that was making integration tests fail
This commit is contained in:
gushuro
2018-02-08 11:45:52 -08:00
committed by Ramya Rao
parent b2483303a3
commit e10ce07e3a
2 changed files with 128 additions and 3 deletions

View File

@@ -33,12 +33,29 @@ export function toggleComment(): Thenable<boolean> | undefined {
}
return editor.edit(editBuilder => {
let allEdits: vscode.TextEdit[][] = [];
editor.selections.reverse().forEach(selection => {
let edits = toggleCommentInternal(editor.document, selection, rootNode!);
edits.forEach(x => {
editBuilder.replace(x.range, x.newText);
});
if (edits.length > 0) {
allEdits.push(edits);
}
});
// Apply edits in order so we can skip nested ones.
allEdits.sort((arr1, arr2) => {
let result = arr1[0].range.start.line - arr2[0].range.start.line;
return result === 0 ? arr1[0].range.start.character - arr2[0].range.start.character : result;
});
let lastEditPosition = new vscode.Position(0, 0);
for (let i = 0; i < allEdits.length; i++) {
const edits = allEdits[i];
if (edits[0].range.end.isAfterOrEqual(lastEditPosition)) {
edits.forEach(x => {
editBuilder.replace(x.range, x.newText);
lastEditPosition = x.range.end;
});
}
}
});
}