From 0a5f4946d3216c6fbaee469e30eb1af8fc96faf4 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 23 Oct 2011 19:09:53 +0000 Subject: [PATCH] Wait until 250 ms after keypress before executing search in QuickFormat Thanks to mronkko for the patch --- chrome/content/zotero/integration/quickFormat.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 66ccec62bc..9c2e0e2706 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -27,6 +27,10 @@ var Zotero_QuickFormat = new function () { var io, qfs, qfi, qfiWindow, qfiDocument, qfe, qfb, qfbHeight, keepSorted, showEditor, referencePanel, referenceBox, referenceHeight, dragX, dragY, curLocator, curLocatorLabel, curIDs = [], curResizer, dragging; + + // A variable that contains the timeout object for the latest onKeyPress event + var eventTimeout = null; + const SHOWN_REFERENCES = 7; /** @@ -697,6 +701,7 @@ var Zotero_QuickFormat = new function () { * Handle return or escape */ function _onQuickSearchKeyPress(event) { + var keyCode = event.keyCode; if(keyCode === event.DOM_VK_RETURN || keyCode === event.DOM_VK_ENTER) { event.preventDefault(); @@ -708,7 +713,10 @@ var Zotero_QuickFormat = new function () { _bubbleizeSelected(); } else if(keyCode === event.DOM_VK_BACK_SPACE) { _resize(); - window.setTimeout(_quickFormat, 0); + + if(Zotero_QuickFormat.eventTimeout) clearTimeout(Zotero_QuickFormat.eventTimeout); + Zotero_QuickFormat.eventTimeout = setTimeout(_quickFormat, 250); + } else if(keyCode === event.DOM_VK_UP) { var selectedItem = referenceBox.selectedItem; var previousSibling; @@ -768,7 +776,8 @@ var Zotero_QuickFormat = new function () { } } else { // Use a timeout so that _quickFormat gets called after update - window.setTimeout(_quickFormat, 0); + if(Zotero_QuickFormat.eventTimeout) clearTimeout(Zotero_QuickFormat.eventTimeout); + Zotero_QuickFormat.eventTimeout = setTimeout(_quickFormat, 250); } }