openstyles / stylus

Stylus - Userstyles Manager
https://add0n.com/stylus.html
GNU General Public License v3.0
5.43k stars 304 forks source link

Do not indent userCSS style CSS rulesets within @-moz-document #1146

Open Gitoffthelawn opened 3 years ago

Gitoffthelawn commented 3 years ago

For userCSS styles, all rulesets inside every @-moz-document get indented. Since every ruleset is typically within a @-moz-document, this causes every ruleset to get indented. When the user doesn't want this, it makes it harder to write and edit userCSS styles.

Also if the functions within the @-moz-document are indented, every ruleset within the scope will get further indented!

For example, let's take this example of nice looking code:

@-moz-document  domain("stackexchange.com"),
        domain("askubuntu.com"),
        domain("mathoverflow.net"),
        domain("serverfault.com"),
        domain("stackapps.com"),
        domain("stackoverflow.com"),
        domain("superuser.com") {

In this example, all rulesets inside the @-moz-document get indented by multiple tab stops! If you use tab stops of 3 or 4 characters, this issue gets amplified, as the number of tabs inserted before domain will have to increase to make the code visually appealing.

I tried toggle smart indent to see if it would help, but alas, it did not.

I'm thinking it is best to exclude @-moz-document as a trigger for auto-indentation.

dnknn commented 3 years ago

You can enable Applies to widget : 2012_18183127

tophf commented 3 years ago

Sounds like a CodeMirror bug but it's worth investigating what we can do here anyway. Personally I like the indents and I don't see a single indent as a problem at all so we'll probably have an option for that or we'll try to be smart and adopt the indent of the first inner line.

tophf commented 3 years ago

Meanwhile, as a workaround for the multi-indent bug:

@-moz-document
domain("stackexchange.com"),
domain("askubuntu.com"),
domain("mathoverflow.net"),
domain("serverfault.com"),
domain("stackapps.com"),
domain("stackoverflow.com"),
domain("superuser.com") {
Gitoffthelawn commented 3 years ago

@tophf

I just ran some additional tests, and the "more than 1 tab indent" issue appears likely to be a CodeMirror bug. I will report it there as well.

Perhaps Stylus can implement a workaround, but the example you provided above is what I've been doing as a manual workaround.

Regarding a single indent, I think that's a personal style preference. Personally, I avoid indents that don't help me understand the code I'm writing. In this case, since everything gets indented, I don't find it helpful, as it only results in more horizontal scrolling of the code. It would be great if Stylus had an option to toggle that behavior.