_content/js: make tab on selection undoable

People often highlight a selection and type tab, hoping to indent it.
Instead, the editor replaces it with a tab. That's fine - some editors work that way.
But the old implementation did not push that edit onto the undo stack,
so that there was no way to get the deleted selection back. Fix that.

Fixes golang/go#41037.

Change-Id: I9f2aa94ac389a3905d07411b0a156dbc66a7ec8a
Reviewed-on: https://go-review.googlesource.com/c/website/+/366535
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Website-Publish: Russ Cox <rsc@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/_content/js/playground.js b/_content/js/playground.js
index 2095a59..aa885e3 100644
--- a/_content/js/playground.js
+++ b/_content/js/playground.js
@@ -293,21 +293,7 @@
 
     // autoindent helpers.
     function insertTabs(n) {
-      // find the selection start and end
-      var start = code[0].selectionStart;
-      var end = code[0].selectionEnd;
-      // split the textarea content into two, and insert n tabs
-      var v = code[0].value;
-      var u = v.substr(0, start);
-      for (var i = 0; i < n; i++) {
-        u += '\t';
-      }
-      u += v.substr(end);
-      // set revised content
-      code[0].value = u;
-      // reset caret position after inserted tabs
-      code[0].selectionStart = start + n;
-      code[0].selectionEnd = start + n;
+      document.execCommand('insertText', false, '\t'.repeat(n));
     }
     function autoindent(el) {
       var curpos = el.selectionStart;