diff --git a/extensions/emmet/src/mergeLines.ts b/extensions/emmet/src/mergeLines.ts index 90895683955..b85511704fd 100644 --- a/extensions/emmet/src/mergeLines.ts +++ b/extensions/emmet/src/mergeLines.ts @@ -20,15 +20,15 @@ export function mergeLines() { return editor.edit(editBuilder => { editor.selections.reverse().forEach(selection => { - let [rangeToReplace, textToReplaceWith] = getRangesToReplace(editor.document, selection, rootNode); - if (rangeToReplace && textToReplaceWith) { - editBuilder.replace(rangeToReplace, textToReplaceWith); + let textEdit = getRangesToReplace(editor.document, selection, rootNode); + if (textEdit) { + editBuilder.replace(textEdit.range, textEdit.newText); } }); }); } -function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Selection, rootNode: Node): [vscode.Range, string] { +function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Selection, rootNode: Node): vscode.TextEdit { let startNodeToUpdate: Node; let endNodeToUpdate: Node; @@ -40,7 +40,7 @@ function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Sel } if (!startNodeToUpdate || !endNodeToUpdate || startNodeToUpdate.start.line === endNodeToUpdate.end.line) { - return [null, null]; + return; } let rangeToReplace = new vscode.Range(startNodeToUpdate.start, endNodeToUpdate.end); @@ -49,5 +49,5 @@ function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Sel textToReplaceWith += document.lineAt(i).text.trim(); } - return [rangeToReplace, textToReplaceWith]; + return new vscode.TextEdit(rangeToReplace, textToReplaceWith); } \ No newline at end of file diff --git a/extensions/emmet/src/splitJoinTag.ts b/extensions/emmet/src/splitJoinTag.ts index 619f06af314..b8949b34188 100644 --- a/extensions/emmet/src/splitJoinTag.ts +++ b/extensions/emmet/src/splitJoinTag.ts @@ -20,21 +20,21 @@ export function splitJoinTag() { return editor.edit(editBuilder => { editor.selections.reverse().forEach(selection => { - let [rangeToReplace, textToReplaceWith] = getRangesToReplace(editor.document, selection, rootNode); - if (rangeToReplace && textToReplaceWith) { - editBuilder.replace(rangeToReplace, textToReplaceWith); + let textEdit = getRangesToReplace(editor.document, selection, rootNode); + if (textEdit) { + editBuilder.replace(textEdit.range, textEdit.newText); } }); }); } -function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Selection, rootNode: Node): [vscode.Range, string] { +function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Selection, rootNode: Node): vscode.TextEdit { let nodeToUpdate: Node = getNode(rootNode, selection.start); let rangeToReplace: vscode.Range; let textToReplaceWith: string; if (!nodeToUpdate) { - return [null, null]; + return; } if (!nodeToUpdate.close) { @@ -54,5 +54,5 @@ function getRangesToReplace(document: vscode.TextDocument, selection: vscode.Sel textToReplaceWith = '/>'; } - return [rangeToReplace, textToReplaceWith]; + return new vscode.TextEdit(rangeToReplace, textToReplaceWith); } \ No newline at end of file diff --git a/extensions/emmet/src/updateImageSize.ts b/extensions/emmet/src/updateImageSize.ts index 11471c888e9..3b4458f0c5c 100644 --- a/extensions/emmet/src/updateImageSize.ts +++ b/extensions/emmet/src/updateImageSize.ts @@ -7,7 +7,7 @@ 'use strict'; -import { TextEditor, Range, Position, window } from 'vscode'; +import { TextEditor, Range, Position, window, TextEdit } from 'vscode'; import * as path from 'path'; import { getImageSize } from './imageSizeHelper'; import { isStyleSheet } from 'vscode-emmet-helper'; @@ -39,8 +39,8 @@ export function updateImageSize() { return Promise.all(allUpdatesPromise).then((updates) => { return editor.edit(builder => { updates.forEach(update => { - update.forEach(([rangeToReplace, textToReplace]) => { - builder.replace(rangeToReplace, textToReplace); + update.forEach((textEdit: TextEdit) => { + builder.replace(textEdit.range, textEdit.newText); }); }); }); @@ -50,7 +50,7 @@ export function updateImageSize() { /** * Updates image size of context tag of HTML model */ -function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<[Range, string][]> { +function updateImageSizeHTML(editor: TextEditor, position: Position): Promise { const src = getImageSrcHTML(getImageHTMLNode(editor, position)); if (!src) { @@ -70,7 +70,7 @@ function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<[R .catch(err => { console.warn('Error while updating image size:', err); return []; }); } -function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promise<[Range, string][]> { +function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promise { let getPropertyInsiderStyleTag = (editor) => { const rootNode = parseDocument(editor.document); const currentNode = getNode(rootNode, position); @@ -87,14 +87,14 @@ function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promis return updateImageSizeCSS(editor, position, getPropertyInsiderStyleTag); } -function updateImageSizeCSSFile(editor: TextEditor, position: Position): Promise<[Range, string][]> { +function updateImageSizeCSSFile(editor: TextEditor, position: Position): Promise { return updateImageSizeCSS(editor, position, getImageCSSNode); } /** * Updates image size of context rule of stylesheet model */ -function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (editor, position) => Property): Promise<[Range, string][]> { +function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (editor, position) => Property): Promise { const src = getImageSrcCSS(fetchNode(editor, position), position); @@ -185,28 +185,28 @@ function getImageSrcCSS(node: Property, position: Position): string { * @param {number} width * @param {number} height */ -function updateHTMLTag(editor: TextEditor, node: HtmlNode, width: number, height: number): [Range, string][] { +function updateHTMLTag(editor: TextEditor, node: HtmlNode, width: number, height: number): TextEdit[] { const srcAttr = getAttribute(node, 'src'); const widthAttr = getAttribute(node, 'width'); const heightAttr = getAttribute(node, 'height'); const quote = getAttributeQuote(editor, srcAttr); const endOfAttributes = node.attributes[node.attributes.length - 1].end; - let edits: [Range, string][] = []; + let edits: TextEdit[] = []; let textToAdd = ''; if (!widthAttr) { textToAdd += ` width=${quote}${width}${quote}`; } else { - edits.push([new Range(widthAttr.value.start, widthAttr.value.end), String(width)]); + edits.push(new TextEdit(new Range(widthAttr.value.start, widthAttr.value.end), String(width))); } if (!heightAttr) { textToAdd += ` height=${quote}${height}${quote}`; } else { - edits.push([new Range(heightAttr.value.start, heightAttr.value.end), String(height)]); + edits.push(new TextEdit(new Range(heightAttr.value.start, heightAttr.value.end), String(height))); } if (textToAdd) { - edits.push([new Range(endOfAttributes, endOfAttributes), textToAdd]); + edits.push(new TextEdit(new Range(endOfAttributes, endOfAttributes), textToAdd)); } return edits; @@ -219,7 +219,7 @@ function updateHTMLTag(editor: TextEditor, node: HtmlNode, width: number, height * @param {number} width * @param {number} height */ -function updateCSSNode(editor: TextEditor, srcProp: Property, width: number, height: number): [Range, string][] { +function updateCSSNode(editor: TextEditor, srcProp: Property, width: number, height: number): TextEdit[] { const rule = srcProp.parent; const widthProp = getCssPropertyFromRule(rule, 'width'); const heightProp = getCssPropertyFromRule(rule, 'height'); @@ -228,24 +228,24 @@ function updateCSSNode(editor: TextEditor, srcProp: Property, width: number, hei const separator = srcProp.separator || ': '; const before = getPropertyDelimitor(editor, srcProp); - let edits: [Range, string][] = []; + let edits: TextEdit[] = []; if (!srcProp.terminatorToken) { - edits.push([new Range(srcProp.end, srcProp.end), ';']); + edits.push(new TextEdit(new Range(srcProp.end, srcProp.end), ';')); } let textToAdd = ''; if (!widthProp) { textToAdd += `${before}width${separator}${width}px;`; } else { - edits.push([new Range(widthProp.valueToken.start, widthProp.valueToken.end), `${width}px`]); + edits.push(new TextEdit(new Range(widthProp.valueToken.start, widthProp.valueToken.end), `${width}px`)); } if (!heightProp) { textToAdd += `${before}height${separator}${height}px;`; } else { - edits.push([new Range(heightProp.valueToken.start, heightProp.valueToken.end), `${height}px`]); + edits.push(new TextEdit(new Range(heightProp.valueToken.start, heightProp.valueToken.end), `${height}px`)); } if (textToAdd) { - edits.push([new Range(srcProp.end, srcProp.end), textToAdd]); + edits.push(new TextEdit(new Range(srcProp.end, srcProp.end), textToAdd)); } return edits;