Skip to content

Commit

Permalink
Emmet wrap individual lines with abbr #31814
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Aug 2, 2017
1 parent 2ccdbe4 commit 211ffdf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions extensions/emmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
}
},
"commands": [
{
"command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation",
"title": "%command.wrapIndividualLinesWithAbbreviation%",
"category": "Emmet"
},
{
"command": "editor.emmet.action.wrapWithAbbreviation",
"title": "%command.wrapWithAbbreviation%",
Expand Down
1 change: 1 addition & 0 deletions extensions/emmet/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"command.wrapWithAbbreviation": "Wrap with Abbreviation",
"command.wrapIndividualLinesWithAbbreviation": "Wrap Individual Lines with Abbreviation",
"command.removeTag": "Remove Tag",
"command.updateTag": "Update Tag",
"command.matchTag": "Go to Matching Pair",
Expand Down
32 changes: 31 additions & 1 deletion extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ExpandAbbreviationInput {
syntax: string;
abbreviation: string;
rangeToReplace: vscode.Range;
textToWrap?: string;
textToWrap?: string | string[];
filters?: string[];
}

Expand Down Expand Up @@ -48,6 +48,36 @@ export function wrapWithAbbreviation(args) {
});
}

export function wrapIndividualLinesWithAbbreviation(args) {
if (!validate(false)) {
return;
}

const editor = vscode.window.activeTextEditor;
if (editor.selection.isEmpty) {
vscode.window.showInformationMessage('Select more than 1 line and try again.');
return;
}

const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation' });
const syntax = getSyntaxFromArgs({ language: editor.document.languageId }) || 'html';
const lines = editor.document.getText(editor.selection).split('\n').map(x => x.trim());

return abbreviationPromise.then(abbreviation => {
if (!abbreviation || !abbreviation.trim() || !isAbbreviationValid(syntax, abbreviation)) { return; }

let input: ExpandAbbreviationInput = {
syntax,
abbreviation,
rangeToReplace: editor.selection,
textToWrap: lines
};

return expandAbbreviationInRange(editor, [input], true);
});

}

export function expandEmmetAbbreviation(args) {
const syntax = getSyntaxFromArgs(args);
if (!syntax || !validate()) {
Expand Down
6 changes: 5 additions & 1 deletion extensions/emmet/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode';
import { DefaultCompletionItemProvider } from './defaultCompletionProvider';
import { expandEmmetAbbreviation, wrapWithAbbreviation } from './abbreviationActions';
import { expandEmmetAbbreviation, wrapWithAbbreviation, wrapIndividualLinesWithAbbreviation } from './abbreviationActions';
import { removeTag } from './removeTag';
import { updateTag } from './updateTag';
import { matchTag } from './matchTag';
Expand All @@ -31,6 +31,10 @@ export function activate(context: vscode.ExtensionContext) {
wrapWithAbbreviation(args);
}));

context.subscriptions.push(vscode.commands.registerCommand('editor.emmet.action.wrapIndividualLinesWithAbbreviation', (args) => {
wrapIndividualLinesWithAbbreviation(args);
}));

context.subscriptions.push(vscode.commands.registerCommand('emmet.expandAbbreviation', (args) => {
expandEmmetAbbreviation(args);
}));
Expand Down

0 comments on commit 211ffdf

Please sign in to comment.