Patch to wait for user to end typing before processing key presses in QuickFormat dialog

6 views
Skip to first unread message

mronkko

unread,
Oct 20, 2011, 8:18:17 AM10/20/11
to zotero-dev
See this forum thread for explanation:

http://forums.zotero.org/discussion/20154/typing-into-quickformat-dialog-is-slow/#Item_1


t3080-la0003:zot...@chnm.gmu.edu mronkko$ svn diff
Index: chrome/content/zotero/integration/quickFormat.js
===================================================================
--- chrome/content/zotero/integration/quickFormat.js (revision 10667)
+++ chrome/content/zotero/integration/quickFormat.js (working copy)
@@ -27,6 +27,10 @@
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,13 @@
* Handle return or escape
*/
function _onQuickSearchKeyPress(event) {
+
+ if(Zotero_QuickFormat.eventTimeout)
clearTimeout(Zotero_QuickFormat.eventTimeout);
+
Zotero_QuickFormat.eventTimeout=setTimeout(_processQuickSearchKeyPress,
500,event);
+ }
+
+ function _processQuickSearchKeyPress(event) {
+
var keyCode = event.keyCode;
if(keyCode === event.DOM_VK_RETURN || keyCode ===
event.DOM_VK_ENTER) {
event.preventDefault();

mronkko

unread,
Oct 20, 2011, 9:20:50 AM10/20/11
to zotero-dev
Disregard this patch for now. I will post a new patch soon.

On Oct 20, 3:18 pm, mronkko <mikko.ron...@tkk.fi> wrote:
> See this forum thread for explanation:
>
> http://forums.zotero.org/discussion/20154/typing-into-quickformat-dia...

mronkko

unread,
Oct 20, 2011, 9:33:55 AM10/20/11
to zotero-dev
This is a patch that is more simple and works better than the
previous. I also decreased the timeout to 250 milliseconds. This is
probably enough for the typing speed of most "power users" that would
be affected by the slowness issue.

Index: chrome/content/zotero/integration/quickFormat.js
===================================================================
--- chrome/content/zotero/integration/quickFormat.js (revision 10667)
+++ chrome/content/zotero/integration/quickFormat.js (working copy)
@@ -27,6 +27,10 @@
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 @@
* 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 @@
_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 @@
}
} 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);

Simon

unread,
Oct 22, 2011, 10:42:12 PM10/22/11
to zotero-dev
Can you post this on gist.github.com (or similar) so that the spacing
and line endings aren't mangled?

Thanks,
Simon

mronkko

unread,
Oct 23, 2011, 7:15:58 AM10/23/11
to zotero-dev
Reply all
Reply to author
Forward
0 new messages