1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 14:53:15 +00:00

Update x-listops.js

Corrected the logic of the 'allafter' filter and added a new 'move' filter.
This commit is contained in:
William Jackson 2015-10-22 16:40:36 +02:00
parent 56d467fb47
commit 3e445b8853

View File

@ -77,6 +77,17 @@ Extended filter operators to manipulate the current list.
return results.slice(count).concat(results.slice(0, count)); return results.slice(count).concat(results.slice(0, count));
}; };
/*
Moves the item named in the operand a number of places forward or backward in the list
*/
exports.move = function (source, operator, options) {
var results = prepare_results(source),
index = results.indexOf(operator.operand),
count = parseInt(operator.suffix) || 1,
marker = results.splice(index, 1);
return results.slice(0, index + count).concat(marker).concat(results.slice(index + count));
};
/* /*
Returns the items from the current list that are after the item named in the operand Returns the items from the current list that are after the item named in the operand
*/ */
@ -87,9 +98,9 @@ Extended filter operators to manipulate the current list.
return []; return [];
} }
if (operator.suffix) { if (operator.suffix) {
return results.slice(index - 1); return results.slice(index);
} }
return results.slice(index); return results.slice(index + 1);
}; };
/* /*