From 5376f4953c24d84314dacc561134b1cb8929af04 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 21 Feb 2019 15:32:36 +0000 Subject: [PATCH 1/2] Add switch for enabling duplicates within filters Along with some suitably eye catching notification messages --- boot/boot.js | 71 ++++++++++++++++++-------- core/_temp_allowDuplicates.tid | 92 ++++++++++++++++++++++++++++++++++ core/messages.multids | 6 +++ 3 files changed, 147 insertions(+), 22 deletions(-) create mode 100644 core/_temp_allowDuplicates.tid create mode 100644 core/messages.multids diff --git a/boot/boot.js b/boot/boot.js index 23cf25b23..1cade02c1 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -76,34 +76,42 @@ Push entries onto an array, removing them first if they already exist in the arr $tw.utils.pushTop = function(array,value) { var t,p; if($tw.utils.isArray(value)) { - // Remove any array entries that are duplicated in the new values - if(value.length !== 0) { - if(array.length !== 0) { - if(value.length < array.length) { - for(t=0; t=0; t--) { - p = value.indexOf(array[t]); - if(p !== -1) { - array.splice(t,1); + } else { + for(t=array.length-1; t>=0; t--) { + p = value.indexOf(array[t]); + if(p !== -1) { + array.splice(t,1); + } } } } - } - // Push the values on top of the main array - array.push.apply(array,value); + // Push the values on top of the main array + Array.prototype.push.apply(array,value); + } } } else { - p = array.indexOf(value); - if(p !== -1) { - array.splice(p,1); + if($tw.config._temp_allowDuplicates) { + array.push(value); + } else { + p = array.indexOf(value); + if(p !== -1) { + array.splice(p,1); + } + array.push(value); } - array.push(value); } return array; }; @@ -339,7 +347,7 @@ $tw.utils.parseStringArray = function(value, allowDuplicate) { match = memberRegExp.exec(value); if(match) { var item = match[1] || match[2]; - if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate)) { + if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate || $tw.config._temp_allowDuplicates)) { results.push(item); names[item] = true; } @@ -2021,15 +2029,25 @@ $tw.loadTiddlersNode = function() { Startup TiddlyWiki */ $tw.boot.startup = function(options) { + var _temp_allowDuplicates; options = options || {}; // Get the URL hash and check for safe mode $tw.locationHash = "#"; if($tw.browser && !$tw.node) { if(location.hash === "#:safe") { $tw.safeMode = true; + } else if(location.hash === "#dupes") { + _temp_allowDuplicates = true; + $tw.locationHash = $tw.utils.getLocationHash(); } else { $tw.locationHash = $tw.utils.getLocationHash(); } + } else { + var p = $tw.boot.argv.indexOf("--dupes"); + if(p !== -1) { + _temp_allowDuplicates = true; + $tw.boot.argv.splice(p,1); + } } // Initialise some more $tw properties $tw.utils.deepDefaults($tw,{ @@ -2038,6 +2056,7 @@ $tw.boot.startup = function(options) { types: {} // hashmap by module type of hashmap of exports }, config: { // Configuration overridables + _temp_allowDuplicates: _temp_allowDuplicates, pluginsPath: "../plugins/", themesPath: "../themes/", languagesPath: "../languages/", @@ -2172,6 +2191,14 @@ $tw.boot.startup = function(options) { if($tw.crypto) { $tw.crypto.updateCryptoStateTiddler(); } + // Warn if using duplicates mode + console.log("\x1b[0;31m--------=====>>>>>> " + $tw.wiki.getTiddler("$:/core/_temp_allowDuplicates/Heading").fields.text + "\x1b[0m"); + console.log("\x1b[0;34m--------=====>>>>>> " + $tw.wiki.getTiddler("$:/core/_temp_allowDuplicates/Warning").fields.text + "\x1b[0m"); + if($tw.config._temp_allowDuplicates) { + console.log("\x1b[0;31m--------=====>>>>>> " + $tw.wiki.getTiddler("$:/core/_temp_allowDuplicates/StatusOn").fields.text + "\x1b[0m"); + } else { + console.log("\x1b[0;32m--------=====>>>>>> " + $tw.wiki.getTiddler("$:/core/_temp_allowDuplicates/StatusOff").fields.text + "\x1b[0m"); + } // Gather up any startup modules $tw.boot.remainingStartupModules = []; // Array of startup modules $tw.modules.forEachModuleOfType("startup",function(title,module) { diff --git a/core/_temp_allowDuplicates.tid b/core/_temp_allowDuplicates.tid new file mode 100644 index 000000000..27633f3ff --- /dev/null +++ b/core/_temp_allowDuplicates.tid @@ -0,0 +1,92 @@ +title: $:/core/_temp_allowDuplicates +tags: $:/tags/AboveStory + +
+ +<$reveal type="match" state="$:/state/_temp_allowDuplicatesWarning" text="hide" default="show"> + +<$button set="$:/state/_temp_allowDuplicatesWarning" setTo="show" class="tc-btn-invisible" style=" + width: 100%; + text-align: left; + fill: #ff0;"> + +{{$:/core/images/warning}} + + + + + +<$reveal type="nomatch" state="$:/state/_temp_allowDuplicatesWarning" text="hide" default="show"> + +<$button set="$:/state/_temp_allowDuplicatesWarning" setTo="hide" class="tc-btn-invisible" style=" + width: 100%; + text-align: left; + fill: #ff0;"> + +{{$:/core/images/chevron-left}} {{$:/core/images/warning}} + + + +
+ +{{$:/core/_temp_allowDuplicates/Heading}} + +
+ +
+ +{{$:/core/_temp_allowDuplicates/Warning}} + +
+ +<$list filter="1 1 1 1 +[butfirst[]limit[1]]" emptyMessage=""" + +
+ +{{$:/core/_temp_allowDuplicates/StatusOff}} + +//Append `#dupes` to the browser address bar to enable// + +
+"""> + +
+ +{{$:/core/_temp_allowDuplicates/StatusOn}} + +//Remove `#dupes` from the browser address bar to disable// + +
+ + + + + +
+ + diff --git a/core/messages.multids b/core/messages.multids new file mode 100644 index 000000000..5fbe5dafa --- /dev/null +++ b/core/messages.multids @@ -0,0 +1,6 @@ +title: $:/core/_temp_allowDuplicates/ + +Heading: Important Warning +Warning: This is a special prerelease version of TW5 for experimenting with a potentially incompatible change to the core logic of filter processing. It is only intended to be used for evaluation and testing +StatusOff: The allow duplicates setting is currently: OFF +StatusOn: The allow duplicates setting is currently: ON From ddec1469251f30b3bbf450a2b781e3832b170bf3 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Wed, 5 Apr 2023 11:53:28 +0100 Subject: [PATCH 2/2] Fix boot.js change from master --- boot/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index a1427061b..72de50d73 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -2312,7 +2312,7 @@ $tw.loadTiddlersNode = function() { /* Startup TiddlyWiki */ -$tw.boot.startup = function(options) { +$tw.boot.initStartup = function(options) { var _temp_allowDuplicates; options = options || {}; // Get the URL hash and check for safe mode