About
Here's yet another Greasemonkey / Tampermonkey userscript for Stack Exchange. It adds the following enhancements:
Within preformatted code blocks, double-click to select all.
In the post editor, this script mimics the behavior of Notepad++ with Tab, Home, End, and Enter.
- The Tab key inserts
\t
. If multiple lines are highlighted, indent all included lines within the selection. - Shift+Tab outdents. If selection doesn't span multiple lines, move cursor backward one tab stop toward the beginning of text, or outdent if already at the beginning of text.
- Home moves the cursor to the previous line wrap, with a double tap moving to the beginning of the line.
- Likewise, End moves the cursor to the next wrap, then to the next
\n
. - Enter continues the previous line's indentation.
- Ctrl+Enter submits the edit.
- The Tab key inserts
Why?
My inspirations for writing this script were the Select Code Block Buttons script and Better handling of indentation and the TAB key.... Both scripts come close, but neither behaves exactly how I expect. The "hover over code block to reveal a select all button" script is a nice idea, but I like a bigger target, and the version I tried from that page interfered with adding comments. Some purists might also appreciate that this double-click method adds no buttons or other visual controls to besmirch the clean UI. The "better handling of indentation" script was also a nice idea, but I felt I could (and believe I did) do it better, making the behavior more closely resemble Notepad++ and adding indent inheritance for carriage returns. And both of those scripts rely on jQuery, whereas mine requires no external libraries. This script is fast enough that I never notice it calculating, even when editing this fairly sizeable question.
Where?
Install Greasemonkey for Firefox or Tampermonkey for Chrome if you haven't already.
Download this script from GitHub. (direct link)
Bug reports / Feature requests
If you find a bug or have a feature request, feel free to post the request as an answer. I can't guarantee I'll implement your request, as this is a script I use to add behavior that I like, which may or may not be what the masses like. I'll consider adding your feature if it's something from which I would personally benefit. Or if the request gets enough upvotes that it would be embarrassing for me to continue ignoring it, I'll add it if I can. Otherwise, it might be quicker for you to learn JavaScript and write it yourself.
Then why is this page here?
Because I worked for several hours on this script, and I thought someone else might get some benefit from it. Because sharing is caring.
License
This script is free and unencumbered software released to the public domain. See license details.