Fix #4752: Category metatags show up as errors in tag edit box.
Fix category prefix metatags not working in autocomplete. Now typing
e.g. `copy:t` will show tags starting with 't' in autocomplete.
Also fix it so that tags beginning with a '(' work in autocomplete.
Typing e.g. `-(tou` will show `touhou` in autocomplete.
This also fixes it so that when you type a negated tag in autocomplete,
e.g. `-touhou`, it sends `touhou` in the autocomplete API call, rather
than `-touhou`. This makes caching more effective since negated tags
will be cached the same as non-negated tags.
This commit is contained in:
@@ -95,8 +95,9 @@ Autocomplete.initialize_tag_autocomplete = function() {
|
|||||||
Autocomplete.current_term = function($input) {
|
Autocomplete.current_term = function($input) {
|
||||||
let query = $input.get(0).value;
|
let query = $input.get(0).value;
|
||||||
let caret = $input.get(0).selectionStart;
|
let caret = $input.get(0).selectionStart;
|
||||||
let match = query.substring(0, caret).match(/\S*$/);
|
let regexp = new RegExp(`^[-~(]*(${Autocomplete.tag_prefixes().join("|")})?`);
|
||||||
return match[0];
|
let match = query.substring(0, caret).match(/\S*$/)[0].replace(regexp, "");
|
||||||
|
return match;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the input field with the item currently focused in the
|
// Update the input field with the item currently focused in the
|
||||||
@@ -106,7 +107,7 @@ Autocomplete.insert_completion = function(input, completion) {
|
|||||||
var before_caret_text = input.value.substring(0, input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, "");
|
var before_caret_text = input.value.substring(0, input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, "");
|
||||||
var after_caret_text = input.value.substring(input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, "");
|
var after_caret_text = input.value.substring(input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, "");
|
||||||
|
|
||||||
var regexp = new RegExp("(" + Autocomplete.tag_prefixes().join("|") + ")?\\S+$", "g");
|
var regexp = new RegExp(`([-~(]*(?:${Autocomplete.tag_prefixes().join("|")})?)\\S+$`, "g");
|
||||||
before_caret_text = before_caret_text.replace(regexp, "$1") + completion + " ";
|
before_caret_text = before_caret_text.replace(regexp, "$1") + completion + " ";
|
||||||
|
|
||||||
input.value = before_caret_text + after_caret_text;
|
input.value = before_caret_text + after_caret_text;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class AutocompleteService
|
|||||||
order: PostQueryBuilder::ORDER_METATAGS
|
order: PostQueryBuilder::ORDER_METATAGS
|
||||||
}
|
}
|
||||||
|
|
||||||
TAG_PREFIXES = ["-", "~"] + TagCategory.mapping.keys.map { |prefix| prefix + ":" }
|
TAG_PREFIXES = TagCategory.mapping.keys.map { |prefix| prefix + ":" }
|
||||||
|
|
||||||
attr_reader :query, :type, :limit, :current_user
|
attr_reader :query, :type, :limit, :current_user
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user