From 11889781746f566564d22c3648500d549ba58b40 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 24 Mar 2008 15:20:57 +0000 Subject: [PATCH] fix issues with spontaneous rearrangement of multi-item citations --- chrome/content/zotero/xpcom/cite.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 9e6281033..90b138699 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -1444,7 +1444,7 @@ Zotero.CSL.prototype._compareItem = function(a, b, context, cache) { } } - // sort by index + // sort by index in document var aIndex = a.getProperty("index"); var bIndex = b.getProperty("index"); if(aIndex !== "" && (bIndex === "" || aIndex < bIndex)) { @@ -1453,6 +1453,15 @@ Zotero.CSL.prototype._compareItem = function(a, b, context, cache) { return 1; } + // sort by old index (to make this a stable sort) + var aOldIndex = a.getProperty("oldIndex"); + var bOldIndex = b.getProperty("oldIndex"); + if(aOldIndex < bOldIndex) { + return -1; + } else if(aOldIndex != bOldIndex) { + return 1; + } + return 0; } @@ -1464,6 +1473,10 @@ Zotero.CSL.prototype.cachedSort = function(items, context, field) { var me = this; var cache = new Object(); + for(var i=0; i