Strengthen sameNodes check 💪 fixes #112829
This commit is contained in:
parent
202a8fa3eb
commit
ea15eb4e5a
|
@ -726,4 +726,29 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
|
|||
});
|
||||
});
|
||||
|
||||
});
|
||||
test('toggle comment doesn\'t fail when start and end nodes differ HTML', () => {
|
||||
const contents = `
|
||||
<div>
|
||||
<p>Hello</p>
|
||||
</div>
|
||||
`;
|
||||
const expectedContents = `
|
||||
<!--<div>
|
||||
<p>Hello</p>
|
||||
</div>-->
|
||||
`;
|
||||
return withRandomFileEditor(contents, 'html', (editor, doc) => {
|
||||
editor.selections = [
|
||||
new Selection(1, 2, 2, 9), // <div> to <p> inclusive
|
||||
];
|
||||
|
||||
return toggleComment().then(() => {
|
||||
assert.equal(doc.getText(), expectedContents);
|
||||
return toggleComment().then(() => {
|
||||
assert.equal(doc.getText(), contents);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -589,11 +589,20 @@ export function getNodesInBetween(node1: Node, node2: Node): Node[] {
|
|||
return siblings;
|
||||
}
|
||||
|
||||
function samePositions(pos1: vscode.Position | undefined, pos2: vscode.Position | undefined): boolean {
|
||||
if (!pos1 && !pos2) {
|
||||
return true;
|
||||
} else if (pos1 && pos2 && pos1.isEqual(pos2)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function sameNodes(node1: Node, node2: Node): boolean {
|
||||
if (!node1 || !node2) {
|
||||
return false;
|
||||
}
|
||||
return (<vscode.Position>node1.start).isEqual(node2.start) && (<vscode.Position>node1.end).isEqual(node2.end);
|
||||
return samePositions(node1.start, node2.start) && samePositions(node1.end, node2.end);
|
||||
}
|
||||
|
||||
export function getEmmetConfiguration(syntax: string) {
|
||||
|
|
Loading…
Reference in a new issue