13

Some people, myself included, thought that buttons to adjust the indentation of code blocks would be useful, since apparently such buttons in all likelihood won't be implemented offically i tried to add this functionality via JavaScript.


Screenshot

The script can be found on GitHub (Source).

The direct link should (prompt for confirmation &) install the script if the browser supports it (i don't know about other browsers but Chrome has some native support and in Firefox you should install the Greasemonkey addon).

Feel free to contribute to and improve* the script, it could do with a more extensive list of includes as it only runs on StackOverflow (and Meta) for now. Another thing that is missing is the automatic preview update, i do not know how to trigger it via code, it should be called after the indentations are executed.

Edits:

  • Script now supports the "new" dynamically added inline editors.

*Two weeks ago i pretty much used JavaScript for the first time, the code is likely to be crap.

6
  • According to Google, "In the latest version of Google Chrome, you must explicitly tell Chrome that you want to install these extensions by adding them through the Extensions page." (that being said, I've tried manually adding the extension -- and it's present -- but it doesn't do anything)
    – Kirk Woll
    Commented Jan 17, 2013 at 2:42
  • @KirkWoll: That is unfortunate and i cannot tell you what might be wrong; i have not tested this on Chrome for a long time and the new extension mechanism is a bit of a pain. I can tell you that it still seems to work on FF if i have the same version installed.
    – brunnerh
    Commented Jan 17, 2013 at 6:49
  • This plugin is not working when editing question or answer on RU StackOverflow, mabe on others. But working on first create. Commented Feb 11, 2018 at 20:14
  • @ДмитрийПолянин: It has not been updated in a long time, so it breaking from changes to the site is highly likely. I'll see if i can fix it...
    – brunnerh
    Commented Feb 12, 2018 at 9:32
  • @ДмитрийПолянин: SO sometimes replaces part of the editor, e.g. when the user is new to the site and the advanced help is shown. This currently messes up the script. I just overhauled the code, but that is something that is not currently handled. Also, the script no longer supports older browsers.
    – brunnerh
    Commented Feb 12, 2018 at 13:45
  • @H.B. thanks. Dont know why but last times all worked on editing too. Commented Feb 12, 2018 at 13:51

1 Answer 1

4

Very cool! Just as a reminder, though, there is some built in functionality worth reminding people about.

Starting with this:

                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");
                            Console.WriteLine("Hello world!");

I highlight it all, then hit nothing but the Code Formatting (aka ctrl+k) button 7 times, and...

Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");
Console.WriteLine("Hello world!");

It will only go in one direction until it hits the end, though that should be sufficient to most purposes. Doing this to your whole code block should keep everything in their proper alignment for your post.

There currently isn't any sort of built-in method to add tabs more than one deep.

1
  • 1
    I am quite aware of this but others might not; One problem is that this backward shifting does not always seem to work (not sure if tab vs. spaces makes a difference) and increasing indentation is helpful for example when having code in a list (which requires 8 spaces indentation).
    – brunnerh
    Commented Jun 7, 2011 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .