Sublime Forum

JSP mode auto-indent after Enter inside bracket pair {} is off by one level of indentation

#1

In a JSP mode file, if I type { at the end of a line, I correctly get the corresponding } immediately after it.

If I then hit Enter, the closing } is indented, but it’s indented one level too far out (to the left).

I’m on the Sublime 3 dev build, latest one I think. It’s a fairly recent regression. It seems to be limited to JSP as far as I can tell; Java and JavaScript files are fine, as is Clojure mode (though I’m less picky there).

0 Likes

#2

Are you using the default Sublime Text syntax? You can open issue for it on: https://github.com/sublimehq/Packages/issues

0 Likes

#3

you can provide exact reproduction steps please? i.e. share some code that we can type to see this happen

The JSP syntax and indenation rules haven’t been changed for 7 months, but the HTML indentation rules were changed 3 months ago, maybe the bug you are experiencing is related to that

0 Likes

#4

Type some stuff, like for example some JSON:

"foo": {

After typing the “{”, the editor will automatically add the matching “}”, so you’ll have

"foo": {}

with the cursor positioned between the braces. If I then hit the Enter key, I get

"foo": {

}

instead of

"foo": {
}
0 Likes

#5

super, thanks, I was able to replicate this in the normal HTML syntax in build 3142.

It looks like it is because the HTML syntax will only indent the next line when the { is the first non-whitespace char on the line https://github.com/sublimehq/Packages/blob/54340707ecbf7de99ab5b02b9414258bd27ed403/HTML/Miscellaneous.tmPreferences#L29, and of course it unindents the }, so it currently unindents when it didn’t indent.

It looks like the fix is to add a .* before the \{[^}"']*$ pattern.

2 Likes

#6

Thanks for looking into this!

0 Likes