Merge pull request #341 from DotJoshJohnson/feature/302-minify-selection
Add Minify XML (Selection) Command and Context Menu Item
This commit is contained in:
commit
dc3d28b962
5 changed files with 34 additions and 3 deletions
|
@ -72,6 +72,10 @@
|
||||||
{
|
{
|
||||||
"command": "xmlTools.minifyXml",
|
"command": "xmlTools.minifyXml",
|
||||||
"title": "XML Tools: Minify XML"
|
"title": "XML Tools: Minify XML"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "xmlTools.minifyXmlSelection",
|
||||||
|
"title": "XML Tools: Minify XML (Selection)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"configuration": {
|
"configuration": {
|
||||||
|
@ -246,6 +250,11 @@
|
||||||
"group": "1_modification@100",
|
"group": "1_modification@100",
|
||||||
"when": "editorLangId == 'xml'"
|
"when": "editorLangId == 'xml'"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "xmlTools.minifyXmlSelection",
|
||||||
|
"group": "1_modification@100",
|
||||||
|
"when": "editorLangId == 'xml' && editorHasSelection"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "xmlTools.getCurrentXPath",
|
"command": "xmlTools.getCurrentXPath",
|
||||||
"group": "z_commands",
|
"group": "z_commands",
|
||||||
|
|
|
@ -6,6 +6,7 @@ export namespace commands {
|
||||||
export const textToXml = "xmlTools.textToXml";
|
export const textToXml = "xmlTools.textToXml";
|
||||||
export const getCurrentXPath = "xmlTools.getCurrentXPath";
|
export const getCurrentXPath = "xmlTools.getCurrentXPath";
|
||||||
export const minifyXml = "xmlTools.minifyXml";
|
export const minifyXml = "xmlTools.minifyXml";
|
||||||
|
export const minifyXmlSelection = "xmlTools.minifyXmlSelection";
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace contextKeys {
|
export namespace contextKeys {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
commands, languages, window, workspace, ExtensionContext, Memento,
|
commands, languages, window, workspace, ExtensionContext, Memento,
|
||||||
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
|
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
|
|
||||||
import { createDocumentSelector, ExtensionState, Configuration } from "./common";
|
import { createDocumentSelector, ExtensionState, Configuration } from "./common";
|
||||||
import { XQueryCompletionItemProvider } from "./completion";
|
import { XQueryCompletionItemProvider } from "./completion";
|
||||||
import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting";
|
import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting";
|
||||||
import { formatAsXml, minifyXml, xmlToText, textToXml } from "./formatting/commands";
|
import { formatAsXml, minifyXml, xmlToText, textToXml, minifyXmlSelection } from "./formatting/commands";
|
||||||
import { XQueryLinter } from "./linting";
|
import { XQueryLinter } from "./linting";
|
||||||
import { XmlTreeDataProvider } from "./tree-view";
|
import { XmlTreeDataProvider } from "./tree-view";
|
||||||
import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
||||||
|
@ -35,6 +35,7 @@ export function activate(context: ExtensionContext) {
|
||||||
commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText),
|
commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText),
|
||||||
commands.registerTextEditorCommand(constants.commands.textToXml, textToXml),
|
commands.registerTextEditorCommand(constants.commands.textToXml, textToXml),
|
||||||
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
||||||
|
commands.registerTextEditorCommand(constants.commands.minifyXmlSelection, minifyXmlSelection),
|
||||||
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||||
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
|
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
|
||||||
);
|
);
|
||||||
|
@ -91,7 +92,7 @@ function _handleContextChange(editor: TextEditor): void {
|
||||||
|
|
||||||
switch (editor.document.languageId) {
|
switch (editor.document.languageId) {
|
||||||
case constants.languageIds.xquery:
|
case constants.languageIds.xquery:
|
||||||
diagnosticCollectionXQuery.set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
diagnosticCollectionXQuery.set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@ export * from "./formatAsXml";
|
||||||
export * from "./minifyXml";
|
export * from "./minifyXml";
|
||||||
export * from "./xmlToText";
|
export * from "./xmlToText";
|
||||||
export * from "./textToXml";
|
export * from "./textToXml";
|
||||||
|
export * from "./minifyXmlSelection";
|
||||||
|
|
19
src/formatting/commands/minifyXmlSelection.ts
Normal file
19
src/formatting/commands/minifyXmlSelection.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { workspace } from "vscode";
|
||||||
|
import { Range, TextEditor, TextEditorEdit } from "vscode";
|
||||||
|
|
||||||
|
import { XmlFormatterFactory } from "../xml-formatter";
|
||||||
|
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||||
|
|
||||||
|
export function minifyXmlSelection(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);
|
||||||
|
|
||||||
|
editor.selections.reverse().forEach(selection => {
|
||||||
|
const range = new Range(selection.start, selection.end);
|
||||||
|
|
||||||
|
edit.replace(range, xmlFormatter.minifyXml(editor.document.getText(range), xmlFormattingOptions));
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue