103

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.

What are your thoughts? Any other issues you have with the editor?

12
  • 37
    I find the lack of intellisense when entering code frustrating too ;)
    – ChrisF Mod
    Commented Jun 29, 2009 at 9:14
  • 6
    I wish that tabs were disallowed completely, but that's just me. (They show up as 8 spaces on IE7, which often means extra scrollbars.)
    – mmyers
    Commented Jun 29, 2009 at 18:03
  • 15
    @mmyers: They could be converted to 4 spaces by SO.
    – musicfreak
    Commented Jun 29, 2009 at 19:12
  • 10
    some of us actually use the tab key for navigation... since that's how every other data entry form on the web works...
    – Kip
    Commented Jun 30, 2009 at 13:57
  • @mmyers, @musicfreak: actually tabs are converted to spaces when displaying the code, it is only in the textarea when creating/editing the text that actual tabs are displayed.
    – Kip
    Commented Jun 30, 2009 at 16:11
  • I doubt, Jeff will do that. He belongs to the spaces front: codinghorror.com/blog/archives/001254.html Commented Jul 22, 2009 at 15:50
  • 8
    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.
    – Randolpho
    Commented Jul 22, 2009 at 17:33
  • 2
    Haters is pretty harsh..
    – Damien
    Commented Jul 22, 2009 at 17:48
  • 5
    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...
    – Addsy
    Commented Jan 11, 2010 at 16:47
  • 3
    +1 @Randolpho for not wanting to change the behavior... except, -1 @Randolpho for using a comment solely to avoid downvotes.
    – Pops
    Commented Sep 25, 2010 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
    Commented Jun 17, 2012 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.
    – user200500
    Commented Jan 6, 2013 at 1:23

18 Answers 18

119

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.)

8
  • 7
    What about Ctrl+] or Ctrl+> for indent? I have found many editors that support at least one of those. Commented Jul 23, 2009 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. Commented Dec 4, 2009 at 5:33
  • yep, liking the auto-indent idea
    – Addsy
    Commented Jan 11, 2010 at 16:47
  • 2
    Never mind the editor - have a +1 for that Google Reader tip.
    – razlebe
    Commented Jan 12, 2012 at 12:24
  • so, let's do this. Commented Oct 14, 2012 at 5:03
  • 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.
    – tchrist
    Commented Jan 6, 2013 at 1:32
  • Someone has worked very hard on a simply javascript implementation here: pallieter.org/Projects/insertTab Commented Jan 17, 2013 at 12:11
  • Everytime I type in code I think that this is missing. What might be the reason it is not implemented yet? Also, see the dedicated thread here: meta.stackexchange.com/questions/146236/…
    – usr
    Commented Jul 24, 2013 at 13:13
63

These shortcuts are found in many / most editors. These would be very useful for putting a code block inside of a list item, for example

  • Ctrl + ] : Indent by 4 spaces
  • Ctrl + > or . : Indent by 4 spaces
  • Ctrl + [ : De-indent by 4 spaces
  • Ctrl + < or , : De-indent by 4 spaces

Other potentially useful keyboard shortcuts.

  • Ctrl + & or 7 : Replace < with &lt; > with &gt; etc (HTML escape special characters)
  • 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.

9
  • I can't +1 this one enough. Great ideas.
    – Randolpho
    Commented Jul 22, 2009 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..
    – dbr
    Commented Sep 4, 2009 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
    Commented Sep 25, 2010 at 22:04
  • @Popular Demand, those are all 2-key combinations. Commented Sep 28, 2010 at 16:13
  • 1
    @Brad, you don't have to hit <kbd>SHIFT</kbd> for any of those?
    – Pops
    Commented Sep 28, 2010 at 16:16
  • @Popular Demand, you do/did for & and !. The first four are the ones I want the most though. Commented Sep 28, 2010 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
    Commented Sep 28, 2010 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?
    – Rookie
    Commented Jun 17, 2012 at 12:31
  • @Pops: Ever worked on the review queue of beginners posts and reindented code properly? There's often cases of having to indent multiple lines (but not all) by four spaces. Selcting text, hitting Ctrl-] or similar would be a very appreciated time saver.
    – cfi
    Commented Sep 25, 2015 at 8:29
11

I stopped using the editor for code editing a long time ago. I just fire up an IDE and do it there, just remember to indent the entire codeblock by one tab and select and copy paste.

11

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.

If you still want to break tab behavior, there's a StackApp for that.

9
  • 2
    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?
    – fretje
    Commented Jun 30, 2009 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
    – Kip
    Commented Jun 30, 2009 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.
    – Damien
    Commented Jul 2, 2009 at 15:46
  • 7
    We're writing code here. Tab is quite natural thing with code. Instead, "Add Comment" could get a shortcut such as Ctrl+Shift+Enter. Commented Jul 10, 2009 at 12:47
  • 1
    @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.
    – Kip
    Commented Jul 10, 2009 at 13:50
  • Shift-tab out or similar.
    – user1228
    Commented Jul 22, 2009 at 16:12
  • 2
    +1. DO NOT CHANGE TAB BEHAVIOR! Look to Jon Skeet and Brad Gilbert for the correct behavior changes.
    – Randolpho
    Commented Jul 22, 2009 at 17:34
  • 2
    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. Commented Aug 8, 2012 at 9:19
  • @RobinMaben: you can make it into a user script and post it on stackapps.com but it looks like a similar script already exists: stackapps.com/questions/3247/…
    – Kip
    Commented Aug 9, 2012 at 13:55
9

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).

2
  • How can we resolve this without taking away features from eveyrone else? Commented Jul 23, 2009 at 0:19
  • 1
    I reported a bug to the Webkit team about this, as I don't think it can be resolved from stackoverflow.com's perspective. Commented Mar 25, 2010 at 20:37
9

I think it would be better if the editor and the preview panes were horizontally aligned, even if it would temporarily hide the right sidebar's content ():

+-------------------------------------------------+
| o o o             Stack Overflow                | 
| < > + - [≥ http://stackoverflow.com/          ] | 
|_[ StackOverflow ][ tab2 ]_______________________| 
|                                                 | 
| B I | @ “ {} [] | < >                           | 
| +---------------------+  +--------------------+ | 
| | Editor source       |  | 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.

2
  • 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.
    – Arjan
    Commented Jun 17, 2012 at 14:36
  • 1
    I think this would really help to stop people posting total nonsense Commented May 18, 2015 at 14:21
8

Priority list IMHO:

  1. Fix the Chrome blockquote bug (or have it fixed)
  2. Make further efforts to match a post's preview and the actual rendering (this list appears correctly in the preview, see item "6")
  3. Autoindentation (see Jon Skeet's answer)
  4. Autoindent lists (so that if I pressed Enter right now, it would move on to item 4)
  5. 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.

1
  • 1
    This is a good example of a broken formatting feature (point 6)
    – scrowler
    Commented May 27, 2014 at 18:41
5

Have the title field as a textarea so that browsers' spell checking functionality works there as well.

my tongue is only slightly in my cheek here

UPDATE I've just discovered that Google Chrome can spell check text boxes, but it appears to be on a per page or site basis as I have to keep re-enabling the option.

3
  • This is a good one actually...
    – Damien
    Commented Jun 30, 2009 at 13:36
  • 7
    In Firefox, about:config - change layout.spellcheckDefault to 2 (Enables spell-check for single line inputs kb.mozillazine.org/Layout.spellcheckDefault )
    – dbr
    Commented Jul 1, 2009 at 3:52
  • 1
    @dbr - didn't know that. I wonder if there's something similar for Chrome?
    – ChrisF Mod
    Commented Jul 1, 2009 at 7:54
4

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.

2
  • Or a title / link fields in the url box. Commented Jun 29, 2009 at 9:46
  • 3
    status-completed
    – badp
    Commented Jan 14, 2011 at 19:56
4

Cheers,

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.

More details here.

3

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.

:-J

0
2

I find it annoying too - especially when writing code, or pasting code in from Visual Studio and then trying to use hightlighting and tabs to move it to the left.

Using "Shift tab" or "Alt tab" (well perhaps not this combination, but you get the idea) might be a compromise.

6
  • 2
    Alt tab? Did you think about that before you suggested it? :P
    – musicfreak
    Commented Jun 29, 2009 at 9:15
  • 1
    No :) - just thinking of a modifier on the tab key. Thanks!
    – ChrisF Mod
    Commented Jun 29, 2009 at 9:18
  • Haha no problem. I had to actually go and try out the combination to see if I found it natural before I realized something was wrong. :)
    – musicfreak
    Commented Jun 29, 2009 at 9:21
  • 1
    Ctrl-Tab switches tabs in the browser (MDI) and Shift-Tab means back-tab. So none of the simple modifiers are available. Commented Jun 29, 2009 at 13:14
  • @Dennis - Damn, but you get the idea - perhaps typing \t then?
    – ChrisF Mod
    Commented Jun 29, 2009 at 13:23
  • 2
    But then what if you want to actually type "\t" - argh!!!
    – ChrisF Mod
    Commented Jun 29, 2009 at 13:24
2

In case anyone wants to try out how it feels live:

Try Codility's Demo test.

It supports both the tab-key and auto-maintains the indentation level. Myself, I love it.

edit: stumbled upon http://compilr.com as well

2

I want to make a case for TAB key adding tab-spaces -

  1. I disagree with this explanation.

  2. When in a code-editor, pressing 'tab' more often than not is because I want to want to add a tab space.

  3. It's what one would expect in that context. And hence more user-friendly than consistency! (Come, on!)

PS : I have even implemented a workaround for textarea fields, I can post it here but not sure that's required/considered.

1
  • It's not a code editor. It is a web page. On web pages, TAB must move between fields. It's an accessibility issue required by law in many jurisdictions. Commented May 18, 2015 at 14:22
2

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.

2

I don't know if this was the case when this question was asked, but Shift+Enter continues the current Markdown line formatting:

In code, I press Shift+Enter
<-- and end up here.
  • Similarly, in a bullet list
  • Shift+Enter put me here.

It doesn't work for a simple formatted block

However,

If you include a space it works again (but you need two spaces at the end of the line
to get this format to display with a new line).

1
  • 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. Commented Feb 24, 2014 at 1:29
1

Please have the tab work in the editing textbox instead of taking the focus elsewhere.

4
  • 3
    "have the tab work in the editing textbox" === "taking the focus elsewhere"
    – Kip
    Commented Jul 22, 2009 at 18:44
  • 1
    @Kip, No if the tab works in the editing textbox, then the focus will stay there and not go elsewhere Commented Jul 22, 2009 at 19:01
  • 1
    not in my web browser
    – Kip
    Commented Jul 22, 2009 at 19:04
  • 1
    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). Commented Jul 22, 2009 at 19:11
0

Please don't force my browser to act like a desktop text editor!

There's already problems with seemingly simple things like trying to give the editor keyboard shortcuts.. For example, the code-block command Ctrl+k invokes the delete-selection emacs'ish command in Camino.

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!

3
  • 1
    Coding community == code-focused editor. Commented Jul 10, 2009 at 12:50
  • 2
    Javascript == crappy basis for a code editor, was more my point!
    – dbr
    Commented Jul 10, 2009 at 14:05
  • 6
    +1. DO NOT CHANGE TAB BEHAVIOR! Look to Jon Skeet and Brad Gilbert for the correct behavior changes.
    – Randolpho
    Commented Jul 22, 2009 at 17:35

You must log in to answer this question.

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