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 :)
Shift-Tabaccessibility shortcut can be achieved (when using your add-on) as follows: 1. Press and hold down
Shiftkey. 2. Press and release
Ctrlwhile still holding down
Shift(text area becomes grey). 3. Press the
Shift-Tabaction will be performed. You can now release the