mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Balance inward should go to inner contents even when no selection Fixes #58173
This commit is contained in:
parent
9504981038
commit
31bf4ccab3
|
@ -87,10 +87,14 @@ function getRangeToBalanceIn(document: vscode.TextDocument, selection: vscode.Se
|
|||
return selection;
|
||||
}
|
||||
|
||||
if (selection.start.isEqual(nodeToBalance.start)
|
||||
&& selection.end.isEqual(nodeToBalance.end)
|
||||
&& nodeToBalance.close) {
|
||||
return new vscode.Selection(nodeToBalance.open.end, nodeToBalance.close.start);
|
||||
if (nodeToBalance.close) {
|
||||
const entireNodeSelected = selection.start.isEqual(nodeToBalance.start) && selection.end.isEqual(nodeToBalance.end);
|
||||
const startInOpenTag = selection.start.isAfter(nodeToBalance.open.start) && selection.start.isBefore(nodeToBalance.open.end);
|
||||
const startInCloseTag = selection.start.isAfter(nodeToBalance.close.start) && selection.start.isBefore(nodeToBalance.close.end);
|
||||
|
||||
if (entireNodeSelected || startInOpenTag || startInCloseTag) {
|
||||
return new vscode.Selection(nodeToBalance.open.end, nodeToBalance.close.start);
|
||||
}
|
||||
}
|
||||
|
||||
if (!nodeToBalance.firstChild) {
|
||||
|
|
|
@ -250,6 +250,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
|
|||
|
||||
editor.selections = [new Selection(12, 7, 12, 7)];
|
||||
let expectedBalanceInRanges: [number, number, number, number][] = [
|
||||
[12, 21, 17, 1], // inner contents of <div class="header">
|
||||
[13, 2, 16, 7], // outer contents of <ul class="nav main">
|
||||
[13, 23, 16, 2], // inner contents of <ul class="nav main">
|
||||
[14, 3, 14, 32], // <li class="item1">Item 1</li>
|
||||
|
@ -293,6 +294,25 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('Emmet Balance In when selection doesnt span entire node or its inner contents', function (): any {
|
||||
return withRandomFileEditor(htmlContents, 'html', (editor, doc) => {
|
||||
|
||||
editor.selection = new Selection(13, 7, 13, 10); // Inside the open tag of <ul class="nav main">
|
||||
balanceIn();
|
||||
testSelection(editor.selection, 23, 13, 2, 16); // inner contents of <ul class="nav main">
|
||||
|
||||
editor.selection = new Selection(16, 4, 16, 5); // Inside the open close of <ul class="nav main">
|
||||
balanceIn();
|
||||
testSelection(editor.selection, 23, 13, 2, 16); // inner contents of <ul class="nav main">
|
||||
|
||||
editor.selection = new Selection(13, 7, 14, 2); // Inside the open tag of <ul class="nav main"> and the next line
|
||||
balanceIn();
|
||||
testSelection(editor.selection, 23, 13, 2, 16); // inner contents of <ul class="nav main">
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
test('Emmet Balance In/Out in html template', function (): any {
|
||||
const htmlTemplate = `
|
||||
<script type="text/html">
|
||||
|
|
Loading…
Reference in a new issue