10

I want to post my code, and use tab to move my cursor blink, but Stack Overflow's question and answer editor uses textarea.

When I use tab, my cursor moves to the tags section.

Does Stack Overflow deliberately do this or is it my keyboard settings?

4
  • 10
    This is pretty typical for all websites. Write your code in your editor and then copy and paste it in into your question.
    – Ben
    Commented Sep 29, 2018 at 11:21
  • Write your mcve in your IDE, so you can compile and future answer. Write your answer in a text editor (an other editor or a text file in your IDE). Past revelant part of your code in your question. Check the code indentation. remove trailing space and convert tab to space(use short cut). Voila. Commented Oct 1, 2018 at 6:54
  • 1
    If you can't compile code with brain. You should always write it in an IDE. Or you could end with "typo/no repro" flag. Commented Oct 1, 2018 at 7:32
  • 1
    This is in no way specific to Stack Overflow. 99% of web forms and even desktop app forms work like this. In order to work any other way you would have to program the page to specifically capture the tab key and make it behave differently. At any rate, this should probably a feature-request.
    – MonkeyZeus
    Commented Oct 1, 2018 at 17:38

2 Answers 2

14

Stack Overflow's code editor doesn't capture the tab key, and as you noted, it's handled by the browser, and just leaves the textarea. You could use four spaces instead. When inputting code in a Stack Overflow answer, I usually just copy such a sequence of spaces and paste it where I need it.

1

As already noted in the accepted answer, this is by default (but for the textarea, not the code editor).

However, a (quite uncomfortable) workaround is using the code snippet (the symbol <> in the toolbar) to write your code: it automatically indents 2 spaces when you hit tab. It's meant for JavaScript, but you can use it the way you want. On top of that, the code snippet has a handy beautifier (named tidy) function.

Here is an example.

function foo(){
  return baz;
  //look ma, I used tab here
};

Of course, you have to remove the lines...

<!- begin snippet: js hide: false console: true babel: false ->

<!- end snippet ->

... that the snippet generates (unless your question is actually about JavaScript and the snippet is runnable).

That being said, the best idea is still using your favourite code editor and copy/pasting the code.

0

You must log in to answer this question.

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