Return cursor position for query object (fixes #228)

Change-Id: I8a7e872dfcce38d2f525d07c1bb3fc84f25250c3
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 80262cc..de9c09b 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -153,6 +153,14 @@
 
 
     /**
+     * Return selection range of the input field.
+     */
+    selectionRange : function () {
+      return this._inputField.selectionRange();
+    },
+
+
+    /**
      * Alert at a specific character position.
      */
     alert : function (charPos, msg) {
diff --git a/dev/js/src/hint/input.js b/dev/js/src/hint/input.js
index cabaa84..520b9e4 100644
--- a/dev/js/src/hint/input.js
+++ b/dev/js/src/hint/input.js
@@ -40,6 +40,16 @@
       window.addEventListener('resize', re);
       this._el.addEventListener('onfocus', re);
       this.reposition();
+
+      // Prevent multiselections
+      this._el.addEventListener("select", () => {
+        const start = this._el.selectionStart;
+        const end = this._el.selectionEnd;
+        if (start !== null && end !== null && start !== end) {
+          this._el.setSelectionRange(start, end);
+        }
+      });
+
       return this;
     },
 
@@ -198,6 +208,13 @@
         value.substring(0, start),
         value.substring(start, value.length)
       );
+    },
+
+    /**
+     * Return the cursor character offsets
+     */
+    selectionRange : function () {
+      return [this._el.selectionStart, this._el.selectionEnd];
     }
   }
 });
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index 76d1a0e..b95d830 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -514,6 +514,9 @@
           if (el = KorAP.vc) {
             v["cq"] = el.toQuery();
           };
+          if (el = KorAP.Hint) {
+            v["selection"] = KorAP.Hint.selectionRange();
+          };
         }
 
         // Get text sigle from match