What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I am sure I am not alone in noticing this, but there seems to be unexpected gui behavior when clicking on the paste code option in questions (and answers) *not when the code is initially highlighted, but as an initial event with the intention of pasting code. Most of the SO users I take it, ask and respond to questions with code that is already formatted in our IDE of choice, yet I have continuously noticed that when one clicks (or uses the hot keys) for pasting code that:

  • indented code is not pasted with the correct indentation.
  • code with no indentation at times only indents the first line.

Probably numerous other examples of how this feature does not work as one would expect. As a user I am suggesting at minimal that pasted code be highlighted automatically so that one can just use hot keys on this or something similar.

Forgive me if I am alone in these issues, but I doubt I am.

share|improve this question
    
I'm not entirely sure what you're getting at. Pasting my formatted code, selecting all of it and then either hitting the code formatting button or ctrl+k works just fine for me. And it preserves all my indentation. What scenario doesn't really work for you. Could you clarify? –  Bart Nov 17 '12 at 22:55
1  
When using the hot keys, one is instructed with a 'paste code here' instruction. Doing so indents the first line more than others. –  thejartender Nov 17 '12 at 22:59
    
Just paste all of your code in, select all of it and then hit the button. Works all the time. –  Bart Nov 17 '12 at 23:00
    
I do. I am bringing attention to the fact that the instructions for this feature are inaccurate. In it's current state as user may interpret it that no such steps are needed. A first time user may visit SO and see the hot keys, paste code and be under the impression that the feature behaved correctly on his behalf and that no such steps are needed. Why is there even an instruction to directly paste it then. This feature comes across as a "step 1" action, but only works correctly as a "step 2 action" as a user must first highlight the code –  thejartender Nov 17 '12 at 23:06
    
Ah, like that. Fair enough –  Bart Nov 17 '12 at 23:13
    
But even with regular use of this site, I argue that a hot key function is appreciated and should behave in a manor where unnecessary actions are reduced. The step of highlighting code can surely be skipped and would benefit user experience. All my code when I post a question here is already indented and one should never have to highlight for "paste" only "cut" or "copy" –  thejartender Nov 17 '12 at 23:26
1  
P.s. Please don't post this in multiple places: meta.serverfault.com/questions/3907/… –  Bart Nov 17 '12 at 23:47
    
It was an accident. I had both open in tabs. I am sorry... –  thejartender Nov 18 '12 at 0:03

1 Answer 1

I'm assuming what you're doing is hitting the "Code Sample" button first, which will give you a line stating:

enter code here

If following that you paste in your code, this will be the result:

int doSomething()

{ return 42; }

That is, only the first line is properly indented and the rest isn't. To prevent that from happening, paste your code in first (without the 4 spaces of indentation for a code block). Then select all of it and hit the button (or ctrl+k). That will then result in this:

int doSomething()
{
    return 42;
}

A code block as we expect it.

share|improve this answer
    
Again, I do this. I am not lazy, but others may be and I see this as unecessary when my IDE has already indented code. To scroll up in SO UI and look for first line of code is hardly user friendly either. –  thejartender Nov 17 '12 at 23:30
    
No need to repeat yourself. I just leave this here as a "currently you have to do this" solution for others, given that what you request does not exist yet. –  Bart Nov 17 '12 at 23:31

You must log in to answer this question.

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