Commit 95fb4e7e authored by matsbla's avatar matsbla Committed by matsbla
Browse files

Issue #3295817 by matsbla: Fix bug introduced by "Tokenize pasted strings"

parent f7bc2323
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
    var separators = e.options.tokenSeparators || [];
    var term = params.term;
    var i = 0;
    var j = 0;

    var createTag = this.createTag || function (params) {
      return {
@@ -27,9 +28,8 @@
      };
    };

    if (term.length && separators.length && $.inArray(term.slice(-1), separators) === -1) {
      term = term + separators[0];
    }
    const item = params.term.split(separators[0]);
    var created = false;

    while (i < term.length) {
      var termChar = term[i];
@@ -54,13 +54,29 @@

      callback(data);

      if (item.length && j + 1 == item.length - 1) {
        const value = item.pop();

        if (value.length) {
          var data = createTag({
            term: value,
          });

          created = true;

          callback(data);
        }
      }

      // Reset the term to not include the tokenized portion
      term = term.substr(i + 1) || '';
      i = 0;

      j++;
    }

    return {
      term: term
      term: !created ? term : '',
    };
  }