forked from external/vscode-xml
Add Minify XML Command
This commit is contained in:
parent
d37a8b70fd
commit
5318909fcf
3 changed files with 26 additions and 1 deletions
|
|
@ -7,7 +7,7 @@ import { XmlFormatterFactory } from "../xml-formatter";
|
|||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export const FormatAsXmlCommandName = "formatAsXml";
|
||||
export const FormatAsXmlCommandName = "xmlTools.formatAsXml";
|
||||
|
||||
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||
const xmlFormattingEditProvider = new XmlFormattingEditProvider(workspace.getConfiguration(constants.extensionPrefix), XmlFormatterFactory.getXmlFormatter());
|
||||
|
|
|
|||
23
src/formatting/commands/minifyXml.ts
Normal file
23
src/formatting/commands/minifyXml.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { commands, workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||
|
||||
import * as constants from "../../constants";
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export const MinifyXmlCommandName = "xmlTools.minifyXml";
|
||||
|
||||
export function minifyXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||
const xmlFormatter = XmlFormatterFactory.getXmlFormatter();
|
||||
const xmlFormattingOptions = XmlFormattingOptionsFactory.getXmlFormattingOptions({
|
||||
insertSpaces: <boolean>editor.options.insertSpaces,
|
||||
tabSize: <number>editor.options.tabSize
|
||||
}, editor.document.eol);
|
||||
|
||||
const endPosition = editor.document.lineAt(editor.document.lineCount - 1).rangeIncludingLineBreak.end;
|
||||
const range = new Range(editor.document.positionAt(0), endPosition);
|
||||
|
||||
edit.replace(range, xmlFormatter.minifyXml(editor.document.getText(), xmlFormattingOptions));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue