Does anyone else have problems with the editor? I may be doing something incredibly stupid, but I find that whenever I use tab I tab out of the box. This is obviously irritating if you're trying to add a code sample.

So it would be quite cool if tab inside the main text box could be used for indenting. I know this would mess up people who like to navigate the form using tab but the content for a question is often large enough to justify it IMO.

I'm not gonna chance getting downvoted by you haters, so I'm going to chime in with the other two folks in negative numbers on this question: don't change tab behavior!! Instead, consider Jon Skeet's or Brad Gilbert's option; preferably both. Do not break web standards for a little comfort. I'm a big fan of the editor, personally, and I frequently find myself wondering why Control-K, Control-L, Control-O, and Control-U won't work when I post on forums or blogs. Make the indenting follow that paradigm, rather than hacking the tab key.
–
RandolphoJul 22 '09 at 17:33

Yeah, the tab button drives me nuts almost every time I post. I know its my own fault but I am so used to pressing tab to indent that I don't even think about it til its too late. Have even managed to submit incomplete answers by pressing tab then enter. These days I try to avoid the editor completely and just use my notepad replacement instead and copy the text in. Still manage to forget sometimes tho...
–
AddsyJan 11 '10 at 16:47

2

+1 @Randolpho for not wanting to change the behavior... except, -1 @Randolpho for using a comment solely to avoid downvotes.
–
Pops♦Sep 25 '10 at 22:03

I would also find this useful on occasion, although... Not as useful in general as being able to tab out from the edit field. Making this apply only when the cursor was in a code section would be an interesting exercise (for someone handy with the userscripts ;-))...
–
Shog9♦Jun 17 '12 at 21:21

Damien, could you please generalise the body of the question so that it deals with only one topic, i.e asking for suggestions to improve the editor? Then you could post your tab key suggestion as an answer.
–
AsadJan 6 '13 at 1:23

18 Answers
18

One very simple one - when writing code, when we hit "enter" it would be really nice if it went to the same indent, i.e.

void Foo()
{
if (foo) <- I'm about to hit enter here
> | <- I would like the cursor to be positioned here

Another request - the Ctrl-K shortcut indents the code if any of it is at the first column, but outdents otherwise. It would be nice to have a shortcut to always indent, so it's easy to indent a whole block of code. (Usually I add an extra line with a character at the start, then select the whole block including the new line, hit Ctrl-K and then remove the extra line, but that's a pain.)

Oh, and finally: a shortcut key to display all the shortcuts as an overlay, like Google Reader does. (Press "?" in Google Reader to see what I mean.)

What about Ctrl+] or Ctrl+> for indent? I have found many editors that support at least one of those.
–
Brad GilbertJul 23 '09 at 0:20

Additionally buttons for an important thing like indent/outdent would be nice, especially for newer users who'd probably mainly look at the editing buttons and not look up short cuts.
–
Georg FritzscheDec 4 '09 at 5:33

yep, liking the auto-indent idea
–
AddsyJan 11 '10 at 16:47

2

Never mind the editor - have a +1 for that Google Reader tip.
–
razlebeJan 12 '12 at 12:24

I strongly agree that once you’ve gotten use to :set autoindent in vi, using a code editor that doesn’t have it is super-frustrating to the point that it no longer seems like a real code editor. I’ve given up trying to enter code in the text boxes; it is far too primitive. So I end up editing the code to insert in a separate vi window, and then use murine snarf-n-barf to transfer the code once done. It’s not for everyone, but at least that way I get a proper code editor without forcing SO to code it up in their text widgets.
–
tchristJan 6 '13 at 1:32

You should be able to paste in the raw URL to a question and the editor will auto-link it with the title of the question. This alone will save me a bunch of time in copying and pasting twice to link a question.

Please do not make tab key insert an actual tab!

Many users (well, at least this one) rely on the tab key to change focus when they are not using their mouse. It would break a fundamental UI feature that's been around in data entry forms (on and off the web) since at least Windows 3.1.

I'd suggest to use spaces if you are entering code in the editor. If you have an unusually large block of code, you're probably copy/pasting from an IDE anyway.

I think a textarea field is the one exeption to this... how would one enter a tab then otherwise, without copying/pasting it from somewhere else?
–
fretjeJun 30 '09 at 13:56

2

well that's how textareas work. like it or not, this site would be different from pretty much everywhere else on the internet. i don't consider that user friendly
–
KipJun 30 '09 at 14:02

2

It wouldn't differ from those that expect large blocks of text. Go try a forum text editor or a e-mail client. Where large text is presumed the tab works as it would in a offline editor.
–
DamienJul 2 '09 at 15:46

@Damien: can you provide some examples of forum text editors or e-mail clients on the web where tab inserts an actual tab? Gmail and Hotmail do not override tab when writing messages. Yahoo overrides it, but even there it doesn't insert a tab, it just does nothing. i tried a couple message boards i'm aware of, and couldn't find any that override tab.
–
KipJul 10 '09 at 13:50

I disagree. When I'm in an editor and I press 'tab' more often than not it's because I want to want to add a tab space. It's what I expect and hence more user-friendly than consistency in this case, at least. Come on! I have even implemented a workaround for textarea fields, I can post it somewhere if I knew where.
–
Robin MabenAug 8 '12 at 9:19

Messing with the inputs indentation really isn't a <textarea>'s job, and that's all the "editor" really is! I imagine such a feature could easily screw with pasting into the input box, for example.

This pushes a simple textarea into the "The Uncanny Valley of User Interface[s]", something I feel the WMD editor has quite successfully avoided (disable Javascript and this box basically works the same, minus the preview)

The editor isn't too bad for writing code.. For single-level-of-indentation code, I generally write it with no indentation, then use the ctrl+k shortcut to indent the first level, then select the rest of the code and hit ctrl+k again.. I'll try and demonstrate..

Step 1 (write script with no indentation):

if(true){
something()
}

Step 2 (select the lines and ctrl+k to indent it):

if(true){
something()
}

Step 3 (remove the extra two lines, select all the code, press ctrl+k to make it into the final code-block):

if(true){
something()
}

If I want to write code with anything more than one level of indentation, I just copy the answer-text into to a proper text editor (which I'm sure most users have open anyway!)

There's a good Firefox addon for this, actually. "It's All Text!" adds a little "Edit" button to each input box.. When clicked it loads the current text into your editor-of-choice.. When you save the file, the textarea is updated and you can post your answer. Same as the copy-and-paste to a proper editor, with less key-strokes!

It was suggested to me that I should post here a request fixing problem with AltGr+G on Croatian keyboards. Basically, AltGr+F is used to insert [, and AltGr+G is used to insert ] on Croatian keyboard.

Overriding system shortcuts is a bad thing. I can no longer paste into the text editing field without using the mouse, using Mac OS X, on a Dvorak/Cmd-Querty keyboard. (Cmd-V converts into "Code", which is Ctrl-K).

That's the problem with SO's textbox, the tab takes the focus elsewhere. After I tab, I always have to mouse-click in the box again (and then use the spacebar repeatedly).
–
Lance RobertsJul 22 '09 at 19:11

Ctrl + ! or 1 : Replace selected text with the final html code
This would be useful when you want a code sample in a blockquote.

It should also be possible to have customized combos that are attached to an account.
Since there are many different variations of keyboards, it would be short-sighted to have only have a hard-coded set of available combos.

I can't +1 this one enough. Great ideas.
–
RandolphoJul 22 '09 at 17:28

Hm.. that could actually work! Auto-indent idea is likely to break pasting, this should work fine as it doesn't screw with default behaviour, just a few extra (otherwise unused) keyboard shortcuts..
–
dbrSep 4 '09 at 12:46

1

Nice idea in theory, but there's no way I'm going to learn a three-key combination instead of just tapping spacebar/backspace four times.
–
Pops♦Sep 25 '10 at 22:04

@Brad, you don't have to hit <kbd>SHIFT</kbd> for any of those?
–
Pops♦Sep 28 '10 at 16:16

@Popular Demand, you do/did for & and !. The first four are the ones I want the most though.
–
Brad GilbertSep 28 '10 at 16:25

1

@Brad, thanks for the edit, but on my keyboard, <kbd>SHIFT</kbd> is required for < and >. I guess you could use CTRL+, and CTRL+. as well.
–
Pops♦Sep 28 '10 at 16:28

1

The problem with these shortcuts is that they only work for American users. For example on my keyboard ] comes from CTRL+ALT+9 combo. So does CTRL+] mean CTRL+CTRL+ALT+9 for me?
–
RookieJun 17 '12 at 12:31

I'd like the editor to write the code I mean, not the code I type. It should be smart enough to correct any usage errors I make due to the lack of intellisense. A unit testing framework that allows me to check my code for errors would be nice, too.

Make further efforts to match a post's preview and the actual rendering (this list appears correctly in the preview, see item "6")

Autoindentation (see Jon Skeet's answer)

Autoindent lists (so that if I pressed Enter right now, it would move on to item 4)

Add a character palette for all sorts of useful characters from m-dashes to backticks and tilde (not everybody has them on their keyboard) to arrows block drawing characters to mathematical operators. For example: (Mr. &shy; makes this look misaligned)

┌─┬┐ αµ ~∀ ±− ­ ↖↑↗ “”
│├┼┤ βϱ `∃ ×² – ←⇔→ ⇐⇒
└─┴┘ πω ¬∈ ÷³ — ↙↓↘ ⊂⊃

6. Make it less annoying to copy and paste data from the post preview.

If the editor area could autogrow, then the actual contents in the source and the preview panes would be approximately aligned, thus extensive vertical scrolling (in the editor area AND the page) could be entirely avoided.

When optional, like if fluently adjusting to your browser's window size, then I would not mind. But I'm rarely using a width that fits 660 pixels twice, and would dislike any site requiring that.
–
ArjanJun 17 '12 at 14:36

I get that the StackOverflow questions/answer box is not for any sort of serious code editing, but a couple toolbar buttons + keyboard shortcuts for performing indent and outdent would be a very nice upgrade. It would benefit both code editing and list editing.

Suggested keyboard shorcuts (keeping in mind that tab and shift-tab are not really a good option within a browser): Ctrl+</Ctrl+> and/or Ctrl+[/Ctrl+]

In addition, being able to maintain the same level of indent when pressing enter would be equally as valuable.

Sure, we could all switch to a dedicated text editor when typing code, but that adds unnecessary friction to the process when you just have a few lines to type. Good user experience is all about minimizing this type of friction, and indenting/outdenting is a pretty common use case.

Interesting observations! The code version puts an 'enter code here' block on the next line, but it is selected so any typing gets rid of it. This isn't a full autoindent; if your line is indented eight spaces (body of function, etc), the shift-enter indents four spaces, not eight. Pity! The bullet list is similar in that it generates some selected text. The bullet list behaves slightly differently depending on whether you have space-asterisk or just asterisk at the start of a line (double spacing if you have no space). And numbered list items are converted to bullet list items.
–
Jonathan LefflerFeb 24 '14 at 1:29