Sublime Forum

Auto-Indent HTML when press enter

#1

Last time, When i press enter between the element, the cursor will indent like that.

Before i press enter:

After I press enter.

Then when i did the latest udpate, this thing just happened.

Please help me fix the issue.

Thanks in advance.

0 Likes

Auto indent in HTML broken
Emmet formatted linebreak not working
#2

I have the latest update and it still formats as

https://forum.sublimetext.com/uploads/default/original/3X/6/e/6e953828ddac21f17d8e38fa56657c26d66fe092.jpg

after hitting enter… it may be a plugin you have thats messing it up

1 Like

#3

I’m having the same problem. Spent the past hour trying to figure it out.

0 Likes

#4

Confirmed on a clean portable ST 3109 Win x64.

0 Likes

#5

it looks like the default keybinding is set to operate on scope meta.scope.between-tag-pair, which is no longer set by the HTML syntax (tested in build 3109) - instead the scope at <div>|</div> is text.html.basic meta.tag.block.any.html punctuation.definition.tag.begin.html, so it will need a fix in the default HTML package. It still works for XML.

Here is the default keybinding:

{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selector", "operator": "equal", "operand": "meta.scope.between-tag-pair", "match_all": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
    ]
}
0 Likes

#6

could it be this commit here @wbond? https://github.com/sublimehq/Packages/commit/57d04205f74069bcfb72a5735e46a1db08b5d8c4

0 Likes

#7

Oh, that is an interesting find. I recently worked on HTML, improving performance and merging in a number of changes. I vaguely remember seeing a match for a pair of HTML tags that ended up breaking other highlighting that took into account the type of tag it was.

I’ll look into getting this functionality working with the current state of the world.

1 Like

#8

@wbond in case it is non-trivial to “fix” the syntax definition while keeping the performance improvements, maybe it is worth considering writing a small, simple on_query_context plugin that the keybinding can use to determine when the cursor is directly between a matching opening and closing tag, what do you think? :wink:

I guess it would be necessary to find out if any plugins make use of this scope, and thus whether it needs to be kept or not… anyway, just an idea :slight_smile:

0 Likes

#9

I’m using ST 3109 Win x64, by the way.

Please help me.

Thanks.

0 Likes

#10

This should be resolved in the next dev build.

0 Likes

#11

Thanks so much @wbond.

0 Likes

#12

Confirmed fixed in 3110 .How did you tackle this in the end @wbond? :slight_smile:

EDIT: if I understand right, you created a new command auto_indent_tag and updated the default keybindings to not require the meta.scope.between-tag-pair scope? :slightly_smiling:

1 Like

#13

Yes, that is correct.

1 Like

#14

I just downloaded Sublime 3, I am still having issues with the auto indent. When I hit enter from the following position (see screenshot) auto-indent does not work (not allowed to add another image but you get the drift; the cursor is not indented).

Before I hit enter:

Thanks

0 Likes

#15

TL;DR: auto indent for HTML only works at <div>|</div> by default - you’ll need to modify the indentation rules to achieve what you want

2 Likes