Consolidate Constants

This commit is contained in:
Josh Johnson 2018-04-28 20:08:28 -04:00
parent bce1b3dd87
commit df45b80085
7 changed files with 53 additions and 26 deletions

View file

@ -7,8 +7,6 @@ import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export const FormatAsXmlCommandName = "xmlTools.formatAsXml";
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
const xmlFormattingEditProvider = new XmlFormattingEditProvider(workspace.getConfiguration(constants.extensionPrefix), XmlFormatterFactory.getXmlFormatter());
const formattingOptions = {
@ -40,11 +38,11 @@ export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
editBuilder.replace(textEdit.range, textEdit.newText);
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
await commands.executeCommand("cursorMove", {
await commands.executeCommand(constants.nativeCommands.cursorMove, {
to: "left",
by: "character"
});
await commands.executeCommand("cursorMove", {
await commands.executeCommand(constants.nativeCommands.cursorMove, {
to: "right",
by: "character"
});

View file

@ -7,8 +7,6 @@ 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({

View file

@ -23,8 +23,9 @@ export class XmlFormatterFactory {
let xmlFormatterImplementation: XmlFormatter;
switch (xmlFormatterImplementationSetting) {
case "classic": xmlFormatterImplementation = new ClassicXmlFormatter(); break;
case "v2": default: xmlFormatterImplementation = new V2XmlFormatter(); break;
case constants.xmlFormatterImplementations.classic: xmlFormatterImplementation = new ClassicXmlFormatter(); break;
case constants.xmlFormatterImplementations.v2:
default: xmlFormatterImplementation = new V2XmlFormatter(); break;
}
return (XmlFormatterFactory._xmlFormatter = xmlFormatterImplementation);

View file

@ -18,9 +18,9 @@ export class XmlFormattingOptionsFactory {
return {
editorOptions: formattingOptions,
newLine: (eol === EndOfLine.CRLF) ? "\r\n" : "\n",
removeCommentsOnMinify: config.get<boolean>("removeCommentsOnMinify"),
splitAttributesOnFormat: config.get<boolean>("splitAttributesOnFormat"),
splitXmlnsOnFormat: config.get<boolean>("splitXmlnsOnFormat")
removeCommentsOnMinify: config.get<boolean>(constants.configKeys.removeCommentsOnMinify),
splitAttributesOnFormat: config.get<boolean>(constants.configKeys.splitAttributesOnFormat),
splitXmlnsOnFormat: config.get<boolean>(constants.configKeys.splitXmlnsOnFormat)
};
}
}