From 4dfa645550771be9f2de2015366f834b05b4b177 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 17 Sep 2019 13:48:09 -0500 Subject: [PATCH] Fix #4169: Tag operators not working with autocomplete. --- .../src/javascripts/autocomplete.js.erb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/javascript/src/javascripts/autocomplete.js.erb b/app/javascript/src/javascripts/autocomplete.js.erb index 77f825138..4899141c1 100644 --- a/app/javascript/src/javascripts/autocomplete.js.erb +++ b/app/javascript/src/javascripts/autocomplete.js.erb @@ -101,9 +101,6 @@ Autocomplete.initialize_tag_autocomplete = function() { if (!metatag && !term) { this.close(); return; - } else if (!metatag && term) { - Autocomplete.normal_source(term, resp); - return; } switch (metatag) { @@ -142,6 +139,9 @@ Autocomplete.initialize_tag_autocomplete = function() { case "search": Autocomplete.saved_search_source(term, resp); break; + case "tag": + Autocomplete.normal_source(term, resp); + break; default: resp([]); break; @@ -271,6 +271,7 @@ Autocomplete.normal_source = function(term, resp) { } Autocomplete.parse_query = function(text, caret) { + var operator = ""; var metatag = ""; var term = ""; @@ -282,9 +283,14 @@ Autocomplete.parse_query = function(text, caret) { return {}; } + match = term.match(/^([-~])(.*)$/); + if (match) { + operator = match[1]; + term = match[2]; + } + match = term.match(Autocomplete.TAG_PREFIXES_REGEX); if (match) { - metatag = match[1].toLowerCase(); term = match[2]; } @@ -292,9 +298,11 @@ Autocomplete.parse_query = function(text, caret) { if (match) { metatag = match[1].toLowerCase(); term = match[2]; + } else { + metatag = "tag"; } - return { metatag: metatag, term: term }; + return { operator: operator, metatag: metatag, term: term }; }; // Update the input field with the item currently focused in the