-
Notifications
You must be signed in to change notification settings - Fork 28.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ''; | ||
|
||
interface ExpandAbbreviationInput { | ||
syntax: string; | ||
abbreviation: string; | ||
|
@@ -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, '')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just assume |
||
previousAbbreviationIndividualLines = inputAbbreviation; | ||
} else { | ||
previousAbbreviation = inputAbbreviation; | ||
} | ||
return revertPromise.then(() => { | ||
const expandAbbrList: ExpandAbbreviationInput[] = rangesToReplace.map(rangesAndContent => { | ||
let rangeToReplace = rangesAndContent.originalRange; | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just assume |
||
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); | ||
}); | ||
|
There was a problem hiding this comment.
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 havingpreviousAbbreviation
is ok.