Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember last abbreviations used in wrap with abbreviation. #46006

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const inlineElements = ['a', 'abbr', 'acronym', 'applet', 'b', 'basefont', 'bdo'
's', 'samp', 'select', 'small', 'span', 'strike', 'strong', 'sub', 'sup',
'textarea', 'tt', 'u', 'var'];

let previousAbbreviation = '';
let previousAbbreviationIndividualLines = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just assume individualLines = true now, so I think just having previousAbbreviation is ok.


interface ExpandAbbreviationInput {
syntax: string;
abbreviation: string;
Expand Down Expand Up @@ -161,13 +164,26 @@ function doWrapping(individualLines: boolean, args: any) {
let extractedResults = helper.extractAbbreviationFromText(inputAbbreviation);
if (!extractedResults) {
return Promise.resolve(inPreview);
} else if (extractedResults.abbreviation !== inputAbbreviation) {
// Not clear what should we do in this case. Warn the user? How?
} else if (extractedResults.abbreviation !== inputAbbreviation.replace(/\|[a-zA-Z]+/g, '')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: is the regex taking out filters? Might be worth adding a comment about it

if (definitive && inPreview) {
// If the final text is not a complete abbreviation, we revert any previews made.
return revertPreview().then(() => {
vscode.window.showErrorMessage('Failed to expand abbreviation ' + inputAbbreviation + '\n' + ' Please check it\'s complete before pressing enter.', 'Ok');
return false;
});
}
// If the text is not a complete abbreviation yet, we don't modify the preview.
return Promise.resolve(inPreview);
}

let { abbreviation, filter } = extractedResults;
if (definitive) {
const revertPromise = inPreview ? revertPreview() : Promise.resolve();
if (individualLines) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just assume individualLines = true now, so there's no need for this check

previousAbbreviationIndividualLines = inputAbbreviation;
} else {
previousAbbreviation = inputAbbreviation;
}
return revertPromise.then(() => {
const expandAbbrList: ExpandAbbreviationInput[] = rangesToReplace.map(rangesAndContent => {
let rangeToReplace = rangesAndContent.originalRange;
Expand Down Expand Up @@ -201,7 +217,8 @@ function doWrapping(individualLines: boolean, args: any) {
}
return '';
}
const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation', validateInput: inputChanged });
let value = individualLines ? previousAbbreviationIndividualLines : previousAbbreviation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just assume individualLines = true now, so there's no need for this check

const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation', validateInput: inputChanged, value, valueSelection: [value.length, value.length] });
return abbreviationPromise.then(inputAbbreviation => {
return makeChanges(inputAbbreviation, true);
});
Expand Down