From 605ee5919a10a66bb9344b32bd8893cd151e1d3c Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Thu, 29 Jun 2017 11:43:52 -0700 Subject: [PATCH] Fix extra tabs when wrapping with inline element #27621 --- extensions/emmet/src/abbreviationActions.ts | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index cdc720e7dde..d99e15cfe3d 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -185,17 +185,35 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex * If there is textToWrap, then given preceedingWhiteSpace is applied */ function expandAbbr(input: ExpandAbbreviationInput, preceedingWhiteSpace: string, newLine: string): string { - + // Expand the abbreviation let expandedText = expand(input.abbreviation, getExpandOptions(input.syntax, input.textToWrap)); if (!expandedText) { return; } + // If no text to wrap, then return the expanded text if (!input.textToWrap) { return expandedText; } - return expandedText.split(newLine).map(line => preceedingWhiteSpace + line).join(newLine); + // There was text to wrap, and the final expanded text is multi line + // So add the preceedingWhiteSpace to each line + if (expandedText.indexOf('\n') > -1) { + return expandedText.split(newLine).map(line => preceedingWhiteSpace + line).join(newLine); + } + + // There was text to wrap and the final expanded text is single line + // This can happen when the abbreviation was for an inline element + // Remove the preceeding newLine + tab and the ending newLine, that was added to textToWrap + // And re-expand the abbreviation + let regex = newLine === '\n' ? /^\n\t(.*)\n$/ : /^\r\n\t(.*)\r\n$/; + let matches = input.textToWrap.match(regex); + if (matches) { + input.textToWrap = matches[1]; + return expandAbbr(input, preceedingWhiteSpace, newLine); + } + + return preceedingWhiteSpace + expandedText; } function getSyntaxFromArgs(args: any): string { -- GitLab