Skip to content

Commit

Permalink
Merge pull request #103677 from amagupta-collab/empty-line-wrap-fix
Browse files Browse the repository at this point in the history
empty-line-wrap-fix
  • Loading branch information
aeschli authored Aug 12, 2020
2 parents 1b29397 + d9b4226 commit edd867f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,25 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
return Promise.resolve(false);
}

/*
* Walks the tree rooted at root and apply function fn on each node.
* if fn return false at any node, the further processing of tree is stopped.
*/
function walk(root: any, fn: ((node: any) => boolean)): boolean {
let ctx = root;
while (ctx) {

let next = ctx.next;
if (fn(ctx) === false || walk(ctx.firstChild, fn) === false) {
return false;
}

ctx = next;
}

return true;
}

/**
* Expands abbreviation as detailed in given input.
*/
Expand Down Expand Up @@ -648,6 +667,18 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
wrappingNode.value = '\n\t' + wrappingNode.value + '\n';
}
}

// Below fixes https://github.com/microsoft/vscode/issues/78219
// walk the tree and remove tags for empty values
walk(parsedAbbr, node => {
if (node.name !== null && node.value === '' && !node.isSelfClosing && node.children.length === 0) {
node.name = '';
node.value = '\n';
}

return true;
});

expandedText = helper.expandAbbreviation(parsedAbbr, expandOptions);
// All $anyword would have been escaped by the emmet helper.
// Remove the escaping backslash from $TM_SELECTED_TEXT so that VS Code Snippet controller can treat it as a variable
Expand Down

0 comments on commit edd867f

Please sign in to comment.