Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Brackets doesn't recognize existing indentation when auto-indenting close braces #8395

Closed
redmunds opened this issue Jul 14, 2014 · 7 comments

Comments

@redmunds
Copy link
Contributor

Start with 2 indented lines where there's an unmatched opening brace on first line and no code on second line:

    if (foo) {

Move cursor to beginning of second line (before indentation, not after) and type closing brace }.

Results:
Brackets adds indentation and then adds the brace. Original indentation is left after the closing brace!

    if (foo) {
    }    

Expected:
Resulting code should not have trailing whitespace.

@peterflynn peterflynn changed the title Brackets doesn't recognize existing indentation Brackets doesn't recognize existing indentation when auto-indenting close braces Jul 15, 2014
@peterflynn
Copy link
Member

Added "...when auto-indenting close braces" to title to clarify when this happens

@redmunds
Copy link
Contributor Author

Note that same problem happens with any auto closing, so "brace" is used generically here.

@peterflynn
Copy link
Member

Yep -- or at least, "electric chars" that can change indent. I think that's only curly braces, square braces, and parens.

@mackenza
Copy link
Contributor

what do you think the proper behavior should be if that 2nd line indent also has text to the right? for instance:

    if (foo) {
    // this is a comment

so then I enter a } to the left of the indent as per the above testcase and end up with:

    if (foo) {
    }    // this is a comment

I suppose what we want to do is indent and remove whitespace to the right of the closing electric?

@redmunds
Copy link
Contributor Author

@mackenza I don't think any whitespace should be removed in that case. Since there are non-whitespace chars on line, then it's all visible, so there are no surprises.

@redmunds
Copy link
Contributor Author

Fix in Progress. Assigning to me while @mackenza works on it.

@redmunds
Copy link
Contributor Author

Confirmed. Closing.

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

No branches or pull requests

3 participants