Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auto indentation when hitting enter inside a tag #52

Closed
fbricon opened this issue Sep 25, 2018 · 4 comments
Closed

Support auto indentation when hitting enter inside a tag #52

fbricon opened this issue Sep 25, 2018 · 4 comments
Assignees
Labels
completion enhancement New feature or request
Milestone

Comments

@fbricon
Copy link
Collaborator

fbricon commented Sep 25, 2018

Similar to the html support in vscode, hitting enter in a xml tag should automatically indent the content.

sep-25-2018 18-23-36

No idea how it's implemented in the html extension. It's probably a client-side feature, but not necessarily.

@fbricon fbricon added enhancement New feature or request completion labels Sep 25, 2018
@fbricon
Copy link
Collaborator Author

fbricon commented Sep 25, 2018

@fbricon
Copy link
Collaborator Author

fbricon commented Sep 28, 2018

In the html extension, this is achieved via those dreadful regexp patterns:

languages.setLanguageConfiguration('html', {
    indentationRules: {
        increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/,
        decreaseIndentPattern: /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/
    },
    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 }
        }
    ],
});

/me needs to throw up

@fbricon fbricon self-assigned this Sep 28, 2018
@fbricon fbricon added this to the 0.2.0 milestone Sep 28, 2018
@fbricon
Copy link
Collaborator Author

fbricon commented Sep 28, 2018

Got a fix. Will PR after I get some shut eye.

@fbricon
Copy link
Collaborator Author

fbricon commented Sep 28, 2018

Tadaaaa

auto-indent-on-enter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant