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

When I ask a question or post an answer in SO, if I want to write the } character, it behaves as if I click on the "Code sample" button (the one with 101010)...

In others words, when I click on the } key *, I get this:

enter code here

or (if I type } in a paragrah):

`enter code here`

Is there any reason that I get this behavior?

How to solve this issue (except by writing a } outside the text area and copy/paste it)?

* important note: I have an AZERTY keyboard, configured for the french langage...

share|improve this question
    
What browser are you using? I've never seen that. It sounds like } may be being confused with Ctrl-K... –  Jon Skeet Sep 1 '09 at 16:03
    
I'm using Firefox 3.5.2, and I am not aware of such a mapping... –  romaintaz Sep 2 '09 at 6:21
    
The } character is on the key used also for '+' and '=', left to the backspace key. If I press this key with AltGr or Ctrl, I get this behavior... –  romaintaz Sep 2 '09 at 6:28
    
I just made the test with IE6 (sorry), and the closing brace is displayed correctly. So maybe this is due to a Firefox plugin? –  romaintaz Sep 2 '09 at 6:32
    
same here, firefox 3.5.5, french azerty keyboard –  mathieu Jan 15 '10 at 23:23

4 Answers 4

up vote 12 down vote accepted

Found the bug!

Explanation

Actually, WMD listens to the keydown event which contains a keyCode and no charCode (only keypress actually contains a charCode) but considers keyCode and charCode to be the same thing.

This is wrong!

Actually, keyCode and charCode may give you the same letter, but that is not true for every letter.

For example:

String.fromCharCode(107) == 'k' // 107 is the charCode for "k"
String.fromCharCode(75) == 'K' // 75 is the keyCode for key K

Wow, the fact that the keyCode of K is the same as the charCode of "K" charCode is only a coincidence (or maybe history). But this is not true for every keys!

For example:

String.fromCharCode(107) == 'k' // 107 is the keyCode for key =
String.fromCharCode(61) == '=' // 61 is the charCode for "="

So when typing k, WMD sees no charCode (since it handles keydown) and uses the keyCode 75 instead which gives K. That's why Ctrl+K is working as expected.

But when typing =, WMD still sees no charCodeand used the keyCode 107 which gives k. Boom, WMD thinks we typed Ctrl+K while we actually typed Ctrl+Alt+= (this is how you type a } on azerty french keyboard).

How to fix it

Actually, it's not that easy.

Relying on the keydown event means that there is no easy way to know what character has been typed, only what key has been typed.

But we can still rely on the keyCode being 75 to trigger our shortcut. This means that it may not be the same letter for everyone.

share|improve this answer
    
excellent, we plan to look at this in the next few weeks. thank you. –  Jeff Atwood May 3 '10 at 23:53
    
I used <kbd> to markup actual keys instead of characters but the rendering is not as nice as in SO. –  Vincent Robert Jun 1 '10 at 11:16
    
It was "fixed" to prevent abuse. @vin –  Gnome Jun 1 '10 at 11:20

}

Works for me! Perhaps your } key is aliased to Ctrl-K, which is the code block shortcut in the editor?

share|improve this answer

I also have the same issue with various versions of firefox v3+, and a French AZERTY keyboard as well. Sometimes I can insert plain closing braces, but not always. The plugins I systematically use are:

  • adblock plus
  • all in one gesture
  • firebug
  • webdevelopper
  • tab mix plus

The bug is not systematic, but very common. I can't tell what changes the times I don't observe it.

It seems to be the same issue as this one about AltGr+Q on German keyboards, and this one on Finish keyboards

share|improve this answer

One way you should be able to include the enclosing brace while this is being fixed - type it in another application, such as Notepad, and then copy/paste it into the input text box.

share|improve this answer
    
We are quite aware of this workaround. Firefox plugins like It's all Text are even better workarounds. –  Luc Hermitte Jun 2 '10 at 13:58

You must log in to answer this question.

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