Fix deep-recursion problem with whitespace trimming in menu prefixes

Change-Id: I30428302ca9847d9728035d1a75909ebd05fb93d
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index db3e968..a60d7ab 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -819,6 +819,24 @@
         expect(menu.shownItem(2)).toBe(undefined);
       });
 
+      it('should be filterable (trimming = " p")', function () {
+        var menu = KorAP.HintMenu.create("/p=", listMultiPrefix);
+        // menu._firstActive = true;
+
+        menu.limit(2);
+        expect(menu.show()).toBe(true);
+        menu._prefix.add(" ");
+        expect(menu.show()).toBe(true);
+        menu._prefix.add("p")
+        expect(menu.show()).toBe(true);
+        expect(menu.shownItem(0).name()).toEqual("PP");
+        expect(menu.element().childNodes[3].innerHTML).toEqual(
+          "<strong><mark>P</mark><mark>P</mark></strong>"+
+            "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>"
+        );
+      });
+
+      
       it('should choose prefix with failing prefix (1)', function () {
         var menu = KorAP.HintMenu.create("cnx/", list);
         menu.limit(2);
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index c3f7fa6..859e109 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -4,7 +4,6 @@
  * @author Nils Diewald
  */
 /*
- * TODO: space is not a valid prefix!
  * TODO: Show the slider briefly on move (whenever screen is called).
  * TODO: Ignore alt+ and strg+ key strokes.
  * TODO: Should scroll to a chosen value after prefixing, if the chosen value is live
diff --git a/dev/js/src/menu/item.js b/dev/js/src/menu/item.js
index 835f69f..812a398 100644
--- a/dev/js/src/menu/item.js
+++ b/dev/js/src/menu/item.js
@@ -179,7 +179,12 @@
 
       // Split prefixes
       if (prefixString) {
-        var prefixes = prefixString.trim().split(" ");
+
+        // ND:
+        //   Doing this in a single line can trigger
+        //   a deep-recursion in Firefox 57.01, though I don't know why.
+        prefixString = prefixString.trim();
+        var prefixes = prefixString.split(" ");
 
         var prefix;
         var testPos;
@@ -237,43 +242,6 @@
 	        p.removeChild(elem);
         };
       };
-
-      /*
-      pos = textlc.indexOf(prefix);
-
-      // Matches!
-      if (pos >= 0) {
-	
-	      // First element
-	      if (pos > 0) {
-	        elem.parentNode.insertBefore(
-	          document.createTextNode(text.substr(0, pos)),
-	          elem
-	        );
-	      };
-	
-	      // Second element
-	      var hl = document.createElement("mark");
-	      hl.appendChild(
-	        document.createTextNode(text.substr(pos, prefix.length))
-	      );
-	      elem.parentNode.insertBefore(hl, elem);
-	
-	      // Third element
-	      var third = text.substr(pos + prefix.length);
-	      if (third.length > 0) {
-	        var thirdE = document.createTextNode(third);
-	        elem.parentNode.insertBefore(
-	          thirdE,
-	          elem
-	        );
-	        this._highlight(thirdE, prefix);
-	      };
-	
-	      var p = elem.parentNode;
-	      p.removeChild(elem);
-      };
-      */
     }
     else {
       var children = elem.childNodes;