mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 22:41:31 +01:00
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:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user