JSFiddle - React, Tailwind, and code Playground

HTML

<a href="#">Bold</a>
<textarea cols="50" rows="10">Thus we were weaving and weaving away when  I started at a sound so strange, long drawn, and musically wild and  unearthly, that the ball of free will dropped from my hand, and I stood  gazing up at the clouds whence that voice dropped like a wing. High  aloft in the cross-trees was that mad Gay-Header, Tashtego. His body was  reaching eagerly forward, his hand stretched out like a wand, and at  brief sudden intervals he continued his cries. To be sure the same sound  was that very moment perhaps being heard all over the seas, from  hundreds of whalemen's look-outs perched as high in the air; but from  few of those lungs could that accustomed old cry have derived such a  marvellous cadence as from Tashtego the Indian's.
  As he stood hovering over you half suspended in air, so wildly and  eagerly peering towards the horizon, you would have thought him some  prophet or seer beholding the shadows of Fate, and by those wild cries  announcing their coming.
  "There she blows! there! there! there! she blows! she blows!"
  "Where-away?"
  "On the lee-beam, about two miles off! a school of them!"
  Instantly all was commotion.
  The Sperm Whale blows as a clock ticks, with the same undeviating and  reliable uniformity. And thereby whalemen distinguish this fish from  other tribes of his genus.
  "There go flukes!" was now the cry from Tashtego; and the whales disappeared.</textarea>

JavaScript

$(function() {
  $("a").click(function() {
    var selStart, selEnd, selText, $textarea, textarea, textareaText;
      
    $textarea = $("textarea");
    textarea = $textarea[0];
    textareaText = $textarea.val();
    selStart = textarea.selectionStart;
    selEnd = textarea.selectionEnd;
    selText = textareaText.substring(selStart, selEnd);
      
    $textarea.val( spliceString(textareaText, selStart, selEnd - selStart, "**" + selText + "**") ).focus();
    textarea.selectionStart = selStart + 2;
    textarea.selectionEnd = selEnd + 2;
  });
});
    
function spliceString(str, index, remove, string2insert) {
  return (str.slice(0, index) + string2insert + str.slice(index + Math.abs(remove)));
}