Tell me more ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

indenting

About

This user script changes the behavior of a few keys (most notably the Tab key) within the post editor to behave more like it does in IDEs or text editors:

  • When multiple lines are selected, Tab and Shift-Tab indent and dedent these lines

  • When nothing is selected, Tab and Shift-Tab insert or remove whitespace to align the cursor on a tab boundary

  • When the cursor is within the left margin of a line, Backspace removes whitespace to align the cursor on a tab boundary (in other words, it may delete more than just one space character)

  • On indented lines, the Home key toggles the cursor between the actual beginning of the line and the beginning of the real content (in other words, it jumps back and forth to before and after the leading whitespace). This only happens on lines that are indented by at least four spaces or a tab, since it can be confusing for the following reason: When you press Home in the text editor, you expect the cursor to jump to the beginning of the line as it is displayed, which (due to wrapping) may be different from the actual previous newline character.

  • So you don't have to reach for the mouse to tab out of the editor you can press and release the Ctrl key, and the next key press will not be intercepted; thus Tab takes you out of the editor. Pressing and releasing Ctrl will grey out the text editor until the next keystroke to clarify this. If you think this is too awkward, I'm open to other suggestions, but there should be some way to tab out of the editor .

Note that this will never insert TAB characters, only spaces. It does however handle already-present TABs, and it handles them the same way the Markdown converter does.

Feedback very welcome, except for discussions about a) tabs vs. spaces, and b) tab width :)

Download

Use one of these two links to install:

share|improve this question
Question: (awesome script by the way!) how does the auto-update feature work around the same-domain restriction for localStorage? – Nathan Osman Mar 23 '12 at 22:20
It doesn't. It checks for updates on every SE site you visit. – balpha Mar 23 '12 at 22:21
Great script, when creating questions. I tried to use its features when editing a question accessed through the review-beta system, with no success. Is this the right place to file this bug? – Spontifixus Sep 26 '12 at 15:17

1 Answer

This uses the jQuery .on(...) feature which is only available in 1.7 and up. Careers is still using an older version and you get an exception on every page right now with this installed.

We will be updating soon, but it would be nice if you could add a config page to turn it on/off for each site.

share|improve this answer
Good point; I've added a check to make sure it's only run on a plain ol' Stack Exchange Q&A site. It wouldn't be a problem to convert this to work with jQuery 1.5, but that isn't really necessary. – balpha Mar 28 '12 at 6:03

You must log in to answer this question.

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