surrounding selected text with parentheses (like Textmate)
<p>I'd like the javascript and HTML for a <code>textarea</code> that surrounds text with parentheses, braces, brackets, and single- or double-quotes when the desired text is selected and one types the 'opening' (left) version of the brace, quote, paren, etc.</p>

<p>For example, if the textarea contains 'A quick brown fox jumped', and 'brown fox' is selected, and I then hit the left-brace key on my keyboard, 'brown fox' should then become surrounded by braces, and be unselected. The same goes for parens, single/double quotes, and brackets.</p>

<p>The solution should work in recent versions of Chrome, FF, and Safari.</p>
