Improve text brackets and parentheses on highlighted text

Currently, when text is highlighted and the user types [ or (, the text is surrounded with brackets or parentheses, but if the user types ] or ), the highlighted text is deleted and replaced with that single character. But it’s easy to mistype closing characters when you intend opening ones. The behavior should be changed so either opening or closing brackets/parentheses surrounds the text properly.