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
- Enter continues the previous line's indentation.
- Ctrl+Enter submits the edit.
- The Tab key inserts
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.
Install Greasemonkey for Firefox or Tampermonkey for Chrome if you haven't already.
Download this script from GitHub. (direct link)
Bug reports / Feature requests
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.
This script is free and unencumbered software released to the public domain. See license details.