diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index d651ac0ec7..4058362a6e 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -242,36 +242,130 @@ var Zotero_QuickFormat = new function () { } } - var ids = (haveConditions ? s.search() : []); - - // no need to refresh anything if box hasnt changed - if(ids.length === curIDs.length) { - var mismatch = false; - for(var i=0; i 50) ids = ids.slice(0, 50); - var items = Zotero.Items.get(ids); + if(searchResultIDs.length && (!citedItems || citedItems.length < 50)) { + // Don't handle more than 50 results + if(searchResultIDs.length > 50-citedItems.length) { + searchResultIDs = searchResultIDs.slice(0, 50-citedItems.length); + } - firstSelectableIndex = 1; - - //TODO: sort the currently used items in before any other items - items.sort(function(a, b) {return a.libraryID > b.libraryID}) + var items = Zotero.Items.get(searchResultIDs); + items.sort(_itemSort); var previousLibrary = -1; - for(var i=0, n=items.length; i 1 + || citationsByItemID[itemID][0].properties.zoteroIndex !== this._fieldIndex))]; + + // Sort all previously cited items at top, and all items cited later at bottom + var fieldIndex = this._fieldIndex; + items.sort(function(a, b) { + var indexA = citationsByItemID[a][0].properties.zoteroIndex, + indexB = citationsByItemID[b][0].properties.zoteroIndex; + + if(indexA >= fieldIndex){ + if(indexB < fieldIndex) return 1; + return indexA - indexB; + } + + if(indexB > fieldIndex) return -1; + return indexB - indexA; + }); + + itemsCallback(Zotero.Items.get(items)); + } +} + /** * Keeps track of all session-specific variables */ diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 7c1727d8e7..c578c384b5 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -581,6 +581,9 @@ integration.revert.button = Revert integration.removeBibEntry.title = The selected references is cited within your document. integration.removeBibEntry.body = Are you sure you want to omit it from your bibliography? +integration.cited = Cited +integration.cited.loading = Loading Cited Items… +integration.ibid = ibid integration.emptyCitationWarning.title = Blank Citation integration.emptyCitationWarning.body = The citation you have specified would be empty in the currently selected style. Are you sure you want to add it?