title: text area getting accurate cursor position on resize
body: <p>I've textarea with no limit of maxlength. As default thing, it displays text in multiple line. Currently it is as follows:</p>
  
  <ul>
  <li>on focus [using mouse pointer], text should move into one line</li>
  <li>the cursor position should capture</li>
  <li>Textarea height to become auto</li>
  <li>the cursor position should move at captured place</li>
  <li>and it should be viewed in the textarea</li>
  </ul>
  
  <p>Can I achieve the same without using <code>setTimeout()</code>. Tried many ways but didn't get output as expected without using <code>setTimeout()</code>.</p>
  
  <p>Any suggestions and comments are highly appreciated. Thank you.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('textarea').focus(function() {
    setTimeout(function() {
      $('textarea').css({
        'height': 'auto',
        'white-space': 'nowrap'
      });
      $('textarea')[0].scrollLeft 
        = (
            $('textarea')[0].selectionStart 
            * (
              $('textarea')[0].scrollWidth / $('textarea').val().length
            )
          ) - 20;
    }, 1);
  });
  $('textarea').blur(function() {
    $(this).css({
      'white-space': 'normal'
    });
    $(this).css({
      'height': $(this)[0].scrollHeight + 'px'
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>textarea#workingTA {
    resize: none;
    border-radius: 5px;
    white-space: nowrap;
    overflow-x: hidden;
    overflow-y: hidden;
    direction: ltr;
    padding: 10px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;textarea id="workingTA" cols="35"&gt;&lt;/textarea&gt;</code></pre>
  </div>
  </div>
  </p>