DEV: adds an experimental `preserveKey` bool option to autocomplete (#12751)

DEV: adds an experimental preserveKey bool option to autocomplete (#12751)

Usage:

$(input).autocomplete({
  preserveKey: false
});

Defaults to true.

diff --git a/app/assets/javascripts/discourse/app/lib/autocomplete.js b/app/assets/javascripts/discourse/app/lib/autocomplete.js
index 2fe20b4..a93bfe6 100644
--- a/app/assets/javascripts/discourse/app/lib/autocomplete.js
+++ b/app/assets/javascripts/discourse/app/lib/autocomplete.js
@@ -85,6 +85,10 @@ export default function (options) {
     return this;
   }
 
+  if (options && typeof options.preserveKey === "undefined") {
+    options.preserveKey = true;
+  }
+
   const disabled = options && options.disabled;
   let wrap = null;
   let autocompleteOptions = null;
@@ -199,7 +203,7 @@ export default function (options) {
           let text = me.val();
           text =
             text.substring(0, completeStart) +
-            (options.key || "") +
+            (options.preserveKey ? options.key || "" : "") +
             term +
             " " +
             text.substring(completeEnd + 1, text.length);

GitHub sha: 99aae959

This commit appears in #12751 which was approved by CvX. It was merged by jjaffeux.