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

[CLOSED] Auto-Identation and Switch Statements #1302

Open
core-ai-bot opened this issue Aug 29, 2021 · 15 comments
Open

[CLOSED] Auto-Identation and Switch Statements #1302

core-ai-bot opened this issue Aug 29, 2021 · 15 comments

Comments

@core-ai-bot
Copy link
Member

Issue by jdiehl
Wednesday Aug 01, 2012 at 09:39 GMT
Originally opened as adobe/brackets#1324


I noticed that the auto-indentation seems to be confused after switch statements. Consider the following (JSLint-approved) code:

function foo(a) {
    "use strict";
    switch (a) {
    case 1:
        break;
    }
}

When hitting enter after the first closing }, auto-indentation inserts 3 tabs (1 would be correct).
When hitting enter after the second closing }, auto-indentation again inserts 3 tabs (0 would be correct).
This goes on, even if additional functions, scopes, whatever are defined, auto-indentation always adds 3 tabs.

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Tuesday Aug 07, 2012 at 17:44 GMT


Reviewed - Move to backlog - card 379.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Tuesday Aug 07, 2012 at 22:14 GMT


I get 2 tabs after both closing curly braces instead of 3, if this is the only text in the file.

This is a CodeMirror bug that repros outside of Brackets as well. I've filed codemirror/codemirror5#708 to track it.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Tuesday Aug 21, 2012 at 20:54 GMT


Looks like the CodeMirror bug has been fixed. It might be a while before we can merge though, since there's been a lot of churn in the scrolling code lately. @jdiehl, do you want to verify the fix upstream in the meantime?

@core-ai-bot
Copy link
Member Author

Comment by jdiehl
Wednesday Aug 22, 2012 at 07:31 GMT


This works on CodeMirror.net, so I guess it is fixed. Thanks for forwarding this.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Saturday Nov 17, 2012 at 08:44 GMT


Reopening -- this won't be fixed in Brackets until we integrate a newer version of CodeMirror

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Friday Jan 11, 2013 at 05:24 GMT


Marked low priority

@core-ai-bot
Copy link
Member Author

Comment by njx
Wednesday Feb 13, 2013 at 01:41 GMT


The worst of this appears to be fixed now that cmv3 is merged--the indentation doesn't "march inward"--but the indentation level of the case statement is too high (it gets indented two tabs worth instead of one, at least when spaces are on). Assigning to me

@core-ai-bot
Copy link
Member Author

Comment by njx
Wednesday Jun 12, 2013 at 01:25 GMT


Filed codemirror/codemirror5#1592 on the latter issue.

@core-ai-bot
Copy link
Member Author

Comment by fdecampredon
Monday Jul 08, 2013 at 22:40 GMT


This is due to the overriding of electricChars on the Editor.
CodeMirror javascript mode double indent every line in a switch statement except the one with case and default at the beginning.
The problem is that in JavaScript Mode the ":" is an electric char (which is not the case of the _checkElectricChars hardcoded RegExp), so in CodeMirror when you type ':' the indentation on case or default lines are updated, what does not happen in brackets.
I guess a simple fix would be to include the ":" in the _checkElectricChars methods. (in fact does this _checkElectricChars methods could be removed ?)

@core-ai-bot
Copy link
Member Author

Comment by njx
Friday Mar 14, 2014 at 23:59 GMT


Low pri but nominating for Brackets 1.0 - it looks like a fix should be possible or easy now (an option was added to CM, and also there's@fdecampredon's note).

@core-ai-bot
Copy link
Member Author

Comment by njx
Friday Apr 11, 2014 at 16:13 GMT


Reviewed. Timebox to half hour.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Aug 15, 2014 at 23:05 GMT


Unfortunately the CM flag added in codemirror/codemirror5#1592 doesn't really help the issue -- it just makes CM insist on intending switch statements completely flat, so things under case aren't indented another stop. And if you manually hit tab on the line under a case, CM will yank the indent level back one every time you hit Enter :-(

It sounds like the real fix is to have _checkElectricChars() trigger on :, but there are several wrinkles there:

  • We probably don't want it in languages other than JS (e.g., typing ":" in the middle of HTML text causing indent to shift around would be weird).
  • We may not want it in non-switch contexts even in JS (e.g. typing an object literal). This seems like the hardest bit to solve, so hopefully it doesn't turn out to be an issue.
  • The current _checkElectricChars() exits early if the electric char isn't the first non-whitespace char on the line. We can't do that in this case because the switch <value> part comes before the :.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Friday Aug 15, 2014 at 23:12 GMT


It also still seems like a bug in CM that the initial line after switch () { is double-indented though, because there's basically no situation where you'd put stuff before the first case statement (and if you did, e.g. some top-level comment, you probably wouldn't want it double-indented either).

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Monday Dec 08, 2014 at 19:06 GMT


Remove 1.1 milestone. We'll take another look at this when we review Marcel's pull request.

@core-ai-bot
Copy link
Member Author

Comment by prafulVaishnav
Thursday Apr 09, 2015 at 02:36 GMT


Fixed by PR #9387 Closing it.

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

No branches or pull requests

1 participant