This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 167597

Summary: CSS: Indentation reset when pressing enter after starting bracket
Product: web Reporter: emilstenstrom <emilstenstrom>
Component: CSS Visual ToolsAssignee: Jan Stola <jstola>
Status: NEW ---    
Severity: blocker    
Priority: P4    
Version: 6.x   
Hardware: Macintosh   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description emilstenstrom 2009-06-24 14:49:13 UTC
I use a somewhat different CSS indentation style, and Netbeans makes it totally unusable by resetting indention before
selectors when pressing enter after a starting bracket.

This is how it looks:
#content {
  background: blue;
}
  #content h1 {
    background: white;
  }

Netbeans makes my live very hard by resetting the indention of the second rule, if I press enter after the opening bracket:

  #content h1 {<press enter here>}

Results in this, with the indention reset:

#content h1 {
  <cursor here>
}

The expected result is this:

  #content h1 {
    <cursor here>
  }

Ie. that the indention is preserved just as if this was an indented if clause in a java file.

(Here's a link about this particular CSS indention style, I know that a few people except me use it:
http://friendlybit.com/css/how-to-structure-large-css-files/ )
Comment 1 emilstenstrom 2009-06-24 15:01:51 UTC
Here's a testcase I think shows the current behavior, resetting the indentation:
http://wiki.netbeans.org/TS_60_CSSeditor#section-TS_60_CSSeditor-TestSuiteCodeEditing -- Scroll down to testcase 9.
Comment 2 David Konecny 2009-08-18 09:36:52 UTC
Unfortunately this will be difficult - line/rule is reindented whenever you type opening or closing bracket, that's a
feature. The formatting you are using make sense - nesting related rules probably improves readability. The problem is
that this rule would have to be added to current CSS formatter and would have to be configurable. Which is probably not
too complicated but I cannot see any resource to implement that right now.
Comment 3 emilstenstrom 2009-08-18 10:38:20 UTC
As far as I'm aware, there are no frequently used indentation styles that have the ending bracket at another level
compared to the selector it closes. To me, that means this needs not to be a configuration option, just a change in how
the indentation works.

When typing a closing bracket:
1) Get the indentation level of the selector of the rule you're in
2) Append that level to each line in the rule, and to the ending bracket

This would also be backwards compatible with the only currently supported formatting, when step 1 yields a indentation
level of zero.

Is this that big of an implementation challenge? It will surely help to push netbeans as a potent CSS Editor.
Comment 4 David Konecny 2009-08-18 22:11:20 UTC
What you are describing is more or less what's happening today. Difference is that if you type '{<press enter here>}'
then both opening and closing bracket are reformatted. You can avoid that by typing space first and then enter in
between brackets - reformatting of opening bracket is done only if enter was pressed just after opening and just before
closing bracket.

Re. "Is this that big of an implementation challenge?" - after I completely rewrote formatters for CSS, HTML and JSP in
NB6.7 formatter's code is quite flexible and change like you are requesting is straightforward to do. What I meant is
that we do not have resources to do the change.
Comment 5 emilstenstrom 2009-08-18 23:11:34 UTC
Ok, I see what you mean. I'm a decent java programmer myself, maybe I can do that change and submit a patch? Could you
point me to the file in question? (or give me a hint of where to start?)
Comment 6 David Konecny 2009-08-19 22:53:30 UTC
Patches are always welcome! Now, I don't want to sound discouraging but because of the size of NetBeans project it might
be overwhelming to start - source code repository is big, there is plethora of modules and APIs and as any other project
of that size there exist vast amount of documentation in different stages of up-to-date-ness. :-) Saying that, best way
to start is to follow http://www.netbeans.org/community/contribute/code.html to get source and build the IDE and read
about providing a patch. Then there is css.editor module (in root of your checkout) which is what you are after and
there is css.editor/src/org/netbeans/modules/css/editor/CssIndenter.java which is good starting point. Have a look.
AbstractIndenter class defined in that module is base class for other formatters (JSP, HTML) and over the time got way
more complicated than what's needed for CSS indentation. Actually, writting formatters sounds really easy at the
beginning but when you start solving problems of JSP templating snippets in the middle of HTML/CSS statements it gets
really really messy. :-)

If you just want to have look at the source code then browse it at
http://hg.netbeans.org/main/file/tip/css.editor/src/org/netbeans/modules/css/editor/CssIndenter.java