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

Auto-indent tag breaks HTML specific indention rules #3018

Open
deathaxe opened this issue Oct 13, 2019 · 3 comments
Open

Auto-indent tag breaks HTML specific indention rules #3018

deathaxe opened this issue Oct 13, 2019 · 3 comments

Comments

@deathaxe
Copy link
Collaborator

Description

The issue described at https://forum.sublimetext.com/t/indentation-when-pressing-enter-html-erb/47006 is caused by the auto_indent_tag text command which is provided by the Default.sublime-package/auto_indent_tag.py module.

The command is bound to the enter key as follows:

	{ "keys": ["enter"], "command": "auto_indent_tag", "context":
		[
			{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "selector", "operator": "equal", "operand": "punctuation.definition.tag.begin", "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": ">$", "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^</", "match_all": true },
		]
	},
	{ "keys": ["shift+enter"], "command": "auto_indent_tag", "context":
		[
			{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "selector", "operator": "equal", "operand": "punctuation.definition.tag.begin", "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": ">$", "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^</", "match_all": true },
		]
	},

Steps to reproduce

  1. Open Sublime Text 3 Vanille Install
  2. Create a new HTML file with the content of (1).
  3. Move the caret to in front of the </h2> (where the pipe is located)
  4. Hit enter

(1)

<html>
<body>
	<h2>
		Text of a <% heading %>|</h2>
</body>
</html>

Expected behavior

The indention level of a closing html tag should be decreased by one if it is moved to the next line, even if there are inline tags/sections like <% ... %> or <? ... ?> in the old line.

after

<html>
<body>
	<h2>
		Text of a <% heading %>
	|</h2>
</body>
</html>

Actual behavior

If inline tags/sections like <% ... %> or <? ... ?> are found in the line, the auto_indent_tag function increases the indention level if a closing tag is moved to the next line.

after

<html>
<body>
	<h2>
		Text of a <% heading %>
			|
		</h2>
</body>
</html>

Suggestions

Remove the module and let the indention rules of the HTML/XML syntax packages handle indention of tags.

If it provides more logic than can be handled via Indention Rules, it should be moved to the related syntax package as it provides syntax specific functionality.

Workaround

To disable the auto_indent_tag until a fix is shipped with ST, a user could overwrite its key binding in order to make the indention rules of the syntax definition apply.

	{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"}, "context":
		[
			{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "selector", "operator": "equal", "operand": "punctuation.definition.tag.begin", "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": ">$", "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^</", "match_all": true },
		]
	},

Environment

  • Build: 3211
  • Operating system and version: all
@gregblass
Copy link

Thank you @deathaxe!!

@gregblass
Copy link

gregblass commented Jan 29, 2020

Any updates on this or plans to address this? It is the bane of my existence.

I'll have to look at the workaround in the mean time.

@gregblass
Copy link

Bump :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants