forked from external/vscode-xml
		
	
							parent
							
								
									276e16b245
								
							
						
					
					
						commit
						ab082e3e0e
					
				
					 5 changed files with 34 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -72,6 +72,10 @@
 | 
			
		|||
            {
 | 
			
		||||
                "command": "xmlTools.minifyXml",
 | 
			
		||||
                "title": "XML Tools: Minify XML"
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                "command": "xmlTools.minifyXmlSelection",
 | 
			
		||||
                "title": "XML Tools: Minify XML (Selection)"
 | 
			
		||||
            }
 | 
			
		||||
        ],
 | 
			
		||||
        "configuration": {
 | 
			
		||||
| 
						 | 
				
			
			@ -246,6 +250,11 @@
 | 
			
		|||
                    "group": "1_modification@100",
 | 
			
		||||
                    "when": "editorLangId == 'xml'"
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "command": "xmlTools.minifyXmlSelection",
 | 
			
		||||
                    "group": "1_modification@100",
 | 
			
		||||
                    "when": "editorLangId == 'xml' && editorHasSelection"
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    "command": "xmlTools.getCurrentXPath",
 | 
			
		||||
                    "group": "z_commands",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ export namespace commands {
 | 
			
		|||
    export const textToXml = "xmlTools.textToXml";
 | 
			
		||||
    export const getCurrentXPath = "xmlTools.getCurrentXPath";
 | 
			
		||||
    export const minifyXml = "xmlTools.minifyXml";
 | 
			
		||||
    export const minifyXmlSelection = "xmlTools.minifyXmlSelection";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export namespace contextKeys {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,12 @@
 | 
			
		|||
import {
 | 
			
		||||
    commands, languages, window, workspace, ExtensionContext, Memento,
 | 
			
		||||
    TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
 | 
			
		||||
    } from "vscode";
 | 
			
		||||
} from "vscode";
 | 
			
		||||
 | 
			
		||||
import { createDocumentSelector, ExtensionState, Configuration } from "./common";
 | 
			
		||||
import { XQueryCompletionItemProvider } from "./completion";
 | 
			
		||||
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 { XmlTreeDataProvider } from "./tree-view";
 | 
			
		||||
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.textToXml, textToXml),
 | 
			
		||||
        commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
 | 
			
		||||
        commands.registerTextEditorCommand(constants.commands.minifyXmlSelection, minifyXmlSelection),
 | 
			
		||||
        languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
 | 
			
		||||
        languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			@ -91,7 +92,7 @@ function _handleContextChange(editor: TextEditor): void {
 | 
			
		|||
 | 
			
		||||
    switch (editor.document.languageId) {
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,3 +2,4 @@ export * from "./formatAsXml";
 | 
			
		|||
export * from "./minifyXml";
 | 
			
		||||
export * from "./xmlToText";
 | 
			
		||||
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