提交 5ed98351 编写于 作者: R Ramya Achutha Rao

Test for Emmet Update Tag #8454

上级 1d000145
......@@ -45,9 +45,12 @@ export function activate(context: vscode.ExtensionContext) {
removeTag();
}));
context.subscriptions.push(vscode.commands.registerCommand('emmet.updateTag', () => {
vscode.window.showInputBox({ prompt: 'Enter Tag' }).then(tagName => {
updateTag(tagName);
context.subscriptions.push(vscode.commands.registerCommand('emmet.updateTag', (inputTag) => {
if (inputTag && typeof inputTag === 'string') {
return updateTag(inputTag);
}
return vscode.window.showInputBox({ prompt: 'Enter Tag' }).then(tagName => {
return updateTag(tagName);
});
}));
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Selection, commands } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
suite('Tests for Emmet: Update Tag', () => {
teardown(closeAllEditors);
const contents = `
<div>
<ul>
<li><span>Hello</span></li>
<li><span>There</span></li>
<div><li><span>Bye</span></li></div>
</ul>
</div>
`;
test('update tag with multiple cursors', () => {
const expectedContents = `
<div>
<ul>
<li><section>Hello</section></li>
<section><span>There</span></section>
<section><li><span>Bye</span></li></section>
</ul>
</div>
`;
return withRandomFileEditor(contents, (editor, doc) => {
editor.selections = [
new Selection(3, 17, 3, 17), // cursor inside tags
new Selection(4, 14, 4, 14), // cursor inside opening tag
new Selection(5, 47, 5, 47), // cursor inside closing tag
];
return commands.executeCommand('emmet.updateTag', 'section').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
});
\ No newline at end of file
......@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { HtmlNode } from 'EmmetNode';
import { getNode, parse, validate } from './util';
export function updateTag(tagName: string) {
export function updateTag(tagName: string): Thenable<boolean> {
let editor = vscode.window.activeTextEditor;
if (!validate(false)) {
return;
......@@ -22,7 +22,7 @@ export function updateTag(tagName: string) {
rangesToUpdate = rangesToUpdate.concat(getRangesToUpdate(editor, selection, rootNode));
});
editor.edit(editBuilder => {
return editor.edit(editBuilder => {
rangesToUpdate.forEach(range => {
editBuilder.replace(range, tagName);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册