From d12f86565089522a0bc65633d443c7fd3a04026d Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 9 Jan 2017 21:47:42 -0400 Subject: [PATCH] [jsx] Automatic HTML indentation and cursor position in JSX. Fixes #18284 --- extensions/typescript/package.json | 1 + extensions/typescript/src/typescriptMain.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index 9f6fdb4d8bc..c8bfa5797d0 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -29,6 +29,7 @@ "onLanguage:javascriptreact", "onLanguage:typescript", "onLanguage:typescriptreact", + "onLanguage:jsx-tags", "onCommand:typescript.reloadProjects", "onCommand:javascript.reloadProjects" ], diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index f8e5908a393..303dbe4b4fd 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -229,6 +229,23 @@ class LanguageProvider { } ] }); + + const EMPTY_ELEMENTS: string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; + + languages.setLanguageConfiguration('jsx-tags', { + wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, + onEnterRules: [ + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i, + action: { indentAction: IndentAction.IndentOutdent } + }, + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + action: { indentAction: IndentAction.Indent } + } + ], + }); }); }