Fix #4731: Tag counter in edit boxes should only count unique tags, not repeated.
Just use the `uniq` function from lodash. Adds ~1kb to the build. Also rename `Utility.regexp_split` to `Utility.splitWords`.
This commit is contained in:
@@ -15,7 +15,9 @@ Blacklist.parse_entry = function(string) {
|
||||
"hits": 0,
|
||||
"min_score": null
|
||||
};
|
||||
Utility.regexp_split(string).forEach(function(tag) {
|
||||
|
||||
let tags = Utility.splitWords(string);
|
||||
tags.forEach(function(tag) {
|
||||
if (tag.charAt(0) === '-') {
|
||||
entry.exclude.push(tag.slice(1));
|
||||
} else if (tag.charAt(0) === '~') {
|
||||
@@ -171,11 +173,11 @@ Blacklist.post_match = function(post, entry) {
|
||||
var score = parseInt($post.attr("data-score"));
|
||||
var score_test = entry.min_score === null || score < entry.min_score;
|
||||
|
||||
var tags = Utility.regexp_split($post.attr("data-tags"));
|
||||
tags.push(...Utility.regexp_split($post.attr("data-pools")));
|
||||
var tags = Utility.splitWords($post.attr("data-tags"));
|
||||
tags.push(...Utility.splitWords($post.attr("data-pools")));
|
||||
tags.push("rating:" + $post.data("rating"));
|
||||
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
||||
Utility.regexp_split($post.data("flags")).forEach(function(v) {
|
||||
Utility.splitWords($post.data("flags")).forEach(function(v) {
|
||||
tags.push("status:" + v);
|
||||
});
|
||||
|
||||
|
||||
@@ -105,7 +105,8 @@ RelatedTag.update_selected = function(e) {
|
||||
}
|
||||
|
||||
RelatedTag.current_tags = function() {
|
||||
return Utility.regexp_split($("#upload_tag_string,#post_tag_string").val().toLowerCase());
|
||||
let tagString = $("#upload_tag_string,#post_tag_string").val().toLowerCase();
|
||||
return Utility.splitWords(tagString);
|
||||
}
|
||||
|
||||
RelatedTag.toggle_tag = function(e) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Utility from "./utility";
|
||||
import uniq from "lodash/uniq";
|
||||
|
||||
export default class TagCounter {
|
||||
static lowCount = 10;
|
||||
@@ -20,7 +21,9 @@ export default class TagCounter {
|
||||
}
|
||||
|
||||
get tagCount() {
|
||||
return Utility.regexp_split(this.$target.val()).length;
|
||||
let tagString = this.$target.val().toLowerCase();
|
||||
let tags = uniq(Utility.splitWords(tagString));
|
||||
return tags.length;
|
||||
}
|
||||
|
||||
get iconName() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Rails from '@rails/ujs';
|
||||
import { hideAll } from 'tippy.js';
|
||||
import words from "lodash/words";
|
||||
|
||||
let Utility = {};
|
||||
|
||||
@@ -113,9 +114,8 @@ Utility.regexp_escape = function(string) {
|
||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||
}
|
||||
|
||||
Utility.regexp_split = function(string) {
|
||||
string ??= "";
|
||||
return string.match(/\S+/g) ?? [];
|
||||
Utility.splitWords = function(string) {
|
||||
return words(string, /\S+/g);
|
||||
}
|
||||
|
||||
$.fn.selectEnd = function() {
|
||||
|
||||
Reference in New Issue
Block a user