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:
evazion
2021-02-23 18:49:53 -06:00
parent 868f1a1809
commit b2a423af64
6 changed files with 29 additions and 17 deletions

View File

@@ -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);
});

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -2,6 +2,14 @@
"license": "MIT",
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.10.5",
"@fontsource/anton": "^4.0.0",
"@fontsource/archivo-narrow": "^4.0.0",
"@fontsource/ibm-plex-mono": "^4.0.0",
"@fontsource/indie-flower": "^4.0.0",
"@fontsource/lora": "^4.0.0",
"@fontsource/petit-formal-script": "^4.0.0",
"@fontsource/rokkitt": "^4.0.0",
"@fontsource/unifrakturmaguntia": "^4.0.0",
"@fortawesome/fontawesome-free": "^5.11.2",
"@rails/ujs": "^6.0.2-1",
"@rails/webpacker": "^6.0.0-beta.4",
@@ -11,6 +19,7 @@
"jquery": "3.5.1",
"jquery-hotkeys": "^0.2.2",
"jquery-ui": "^1.12.1",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^1.3.4",
"postcss": "^8.2.4",
"postcss-flexbugs-fixes": "^5.0.2",
@@ -22,14 +31,6 @@
"sass-loader": "^11.0.0",
"spark-md5": "^3.0.0",
"tippy.js": "^6.2.3",
"@fontsource/anton": "^4.0.0",
"@fontsource/archivo-narrow": "^4.0.0",
"@fontsource/ibm-plex-mono": "^4.0.0",
"@fontsource/indie-flower": "^4.0.0",
"@fontsource/lora": "^4.0.0",
"@fontsource/petit-formal-script": "^4.0.0",
"@fontsource/rokkitt": "^4.0.0",
"@fontsource/unifrakturmaguntia": "^4.0.0",
"typopro-web": "^4.2.2",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0"

View File

@@ -4123,6 +4123,11 @@ lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.19, lodash@^4.17.20:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
log-symbols@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.0.0.tgz#69b3cc46d20f448eccdb75ea1fa733d9e821c920"