From 4b8a6c6c43c8eb0f9dd642f59f9cbe690dbf5aed Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 11 Feb 2024 16:40:44 +0000 Subject: [PATCH] [autocomplete] complete negative searches, fixes #1028 --- ext/autocomplete/script.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/autocomplete/script.js b/ext/autocomplete/script.js index 35eb01f4..5c391439 100644 --- a/ext/autocomplete/script.js +++ b/ext/autocomplete/script.js @@ -42,7 +42,8 @@ function updateCompletions(element) { } else { element.completer_timeout = setTimeout(() => { - fetch((document.body.getAttribute("data-base-href") ?? "") + '/api/internal/autocomplete?s=' + word).then( + const wordWithoutMinus = word.replace(/^-/, ''); + fetch((document.body.getAttribute("data-base-href") ?? "") + '/api/internal/autocomplete?s=' + wordWithoutMinus).then( (response) => response.json() ).then((json) => { if(element.selected_completion !== -1) { @@ -97,7 +98,7 @@ function renderCompletions(element) { Object.keys(completions).filter( (key) => { let k = key.toLowerCase(); - let w = word.toLowerCase(); + let w = word.replace(/^-/, '').toLowerCase(); return (k.startsWith(w) || k.split(':').some((k) => k.startsWith(w))) } ).slice(0, 100).forEach((key, i) => { @@ -176,6 +177,9 @@ function setCompletion(element, new_word) { } // replace the word with the completion + if(text[start] === '-') { + new_word = '-' + new_word; + } new_word += ' '; element.value = text.substring(0, start) + new_word + text.substring(end); element.selectionStart = start + new_word.length;