From f6ad09987ddabc62bf9547935295d145f5d4e699 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 29 Dec 2018 19:33:40 +0300 Subject: [PATCH] reworked .untag2(..), still thinking about it... Signed-off-by: Alex A. Naanou --- ui (gen4)/imagegrid/tags.js | 58 ++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/ui (gen4)/imagegrid/tags.js b/ui (gen4)/imagegrid/tags.js index f8bcb6c5..2336cd12 100755 --- a/ui (gen4)/imagegrid/tags.js +++ b/ui (gen4)/imagegrid/tags.js @@ -1292,6 +1292,7 @@ var BaseTagsPrototype = { return this.rename(tag, '', ...tags) }, // + // Remove tags... // .untag(tags) // .untag(tags, '*') // -> this @@ -1307,9 +1308,17 @@ var BaseTagsPrototype = { // "a" - untag only explicit a // *a* - remove all tags containing a // + // XXX EXPERIMENTAL... + // XXX this will incorrectly rename sets... + // .untag('a:c') // will not correctly rename tag 'a:b:c'... untag2: function(tag, value, ...tags){ var that = this - value = value || '*' + value = !value ? + '*' + : value instanceof Array ? + value + : [value] + var index = this.__index || {} ;(tag instanceof Array ? tag : [tag]) .forEach(function(tag){ @@ -1319,26 +1328,51 @@ var BaseTagsPrototype = { var base = /[\\\/]['"]?\s*$/.test(tag) tag = that.normalize(starred ? tag.trim().slice(1, -1) : tag) + var pattern = !quoted && !starred + && new RegExp( + `(^|[${that.SET_SEPARATOR}\\${that.PATH_SEPARATOR}])` + +`${tag}` + +`(?=$|[${that.SET_SEPARATOR}\\${that.PATH_SEPARATOR}])`, 'g') + var target = `$1` + return that .replace(tag, function(t){ + // skip tags without values (.persistent only) + if(index[t] == null){ + return + } + // special case: literal match... if(quoted){ - // XXX need to account for values... - return tag == t ? '' : t + tag == t && console.log('REMOVE:', t) + tag == t + && (value == '*' ? + (delete index[t]) + : (index[t] = index[t].subtract(value))) - // special case: remove contained... + // special case: remove all matching tags... } else if(starred){ - // XXX need to account for values... - return that.directMatch(tag, t) ? '' : t + value == '*' ? + (delete index[t]) + : (index[t] = index[t].subtract(value)) // replace occurrence... } else { + var values = value == '*' ? + index[t] + : value + // remove from old tag... + value == '*' ? + (delete index[t]) + : (index[t] = index[t].subtract(value)) + + var renamed = that.normalize(t.replace(pattern, target)) + // add to modified tag... + renamed != '' + && (index[renamed] = (index[renamed] || new Set()).unite(values)) } - - }, ...tags) - }) - + }, ...tags) }) return this }, @@ -1514,9 +1548,7 @@ var BaseTagsPrototype = { : 'toggle' tags = normalizeSplit(tags) - var persistent = - this.persistent = - this.persistent || new Set() + var persistent = this.persistent = this.persistent || new Set() return this.normalize(tags) .map(function(tag){