From 7d7fabd4a2860d0c8aee172c6c73a3e3eda7cd3a Mon Sep 17 00:00:00 2001 From: Bognaum Date: Fri, 26 Aug 2022 15:26:35 +0300 Subject: [PATCH] Added the auto indent setting. --- package.json | 25 +++++++++++++++---------- src/extension.js | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 1959317..3c3eeaf 100644 --- a/package.json +++ b/package.json @@ -65,16 +65,21 @@ "configuration": { "title": "Split HTML Attributes", "properties": { - "splitHTMLAttributes.tabSize": { - "type": "number", - "default": 2, - "description": "Number of spaces for indentation.", - "scope": "resource" - }, - "splitHTMLAttributes.useSpacesForTabs": { - "type": "boolean", - "default": true, - "description": "Use spaces for tabs.", + "splitHTMLAttributes.indentType": { + "type": "string", + "default": "Auto", + "enum": [ + "Auto", + "Tab", + "Spaces 0", + "Spaces 1", + "Spaces 2", + "Spaces 3", + "Spaces 4", + "Spaces 5", + "Spaces 6" + ], + "description": "What indents to use.", "scope": "resource" }, "splitHTMLAttributes.closingBracketOnNewLine": { diff --git a/src/extension.js b/src/extension.js index 6509d48..0079908 100644 --- a/src/extension.js +++ b/src/extension.js @@ -23,10 +23,21 @@ function activate(context) { // get config let config = vscode.workspace.getConfiguration('splitHTMLAttributes', editor.document.uri) - let tabSize = config.get("tabSize") - let useSpacesForTabs = config.get("useSpacesForTabs") let closingBracketOnNewLine = config.get("closingBracketOnNewLine") let sortOrder = config.get("sortOrder") + + // get indent options + let tabSize, useSpacesForTabs, indentType = config.get("indentType"); + if (indentType.toLowerCase() === "auto") { + tabSize = editor.options.tabSize + useSpacesForTabs = editor.options.insertSpaces + } else if (indentType.toLowerCase() === "tab") { + tabSize = 1; + useSpacesForTabs = false; + } else { + tabSize = parseInt(indentType); + useSpacesForTabs = true; + } // get document & selection const document = editor.document