Fix conflict with Cmd-Shift-A, and probably other third-party shortcuts
The Zotero shortcut keys, and their event.preventDefault(), were bound to keydown, so shortcuts bound to keypress were still be called. This moves most of the shortcut handling code into the keypress handler. Fixes #344
This commit is contained in:
parent
4d9191ccd8
commit
30a0bbcca2
3 changed files with 137 additions and 134 deletions
|
@ -167,24 +167,28 @@ Zotero.ItemTreeView.prototype._setTreeGenerator = function(treebox)
|
|||
return;
|
||||
}
|
||||
|
||||
var key = String.fromCharCode(event.which);
|
||||
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
|
||||
self.expandAllRows();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
else if (key == '-' && !(event.shiftKey || event.ctrlKey || event.altKey || event.metaKey)) {
|
||||
self.collapseAllRows();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore other non-character keypresses
|
||||
if (!event.charCode) {
|
||||
if (!event.charCode || event.shiftKey || event.ctrlKey ||
|
||||
event.altKey || event.metaKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
Q.fcall(function () {
|
||||
var key = String.fromCharCode(event.which);
|
||||
if (key == '+' && !(event.ctrlKey || event.altKey || event.metaKey)) {
|
||||
self.expandAllRows();
|
||||
return false;
|
||||
}
|
||||
else if (key == '-' && !(event.shiftKey || event.ctrlKey || event.altKey || event.metaKey)) {
|
||||
self.collapseAllRows();
|
||||
return false;
|
||||
}
|
||||
else if (coloredTagsRE.test(key)) {
|
||||
if (coloredTagsRE.test(key)) {
|
||||
let libraryID = self._itemGroup.libraryID;
|
||||
libraryID = libraryID ? parseInt(libraryID) : 0;
|
||||
let position = parseInt(key) - 1;
|
||||
|
|
|
@ -510,9 +510,63 @@ var ZoteroPane = new function()
|
|||
}
|
||||
ZoteroPane_Local.collectionsView.setHighlightedRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handleKeyUp(event, from) {
|
||||
if (from == 'zotero-pane') {
|
||||
if ((Zotero.isWin && event.keyCode == 17) ||
|
||||
(!Zotero.isWin && event.keyCode == 18)) {
|
||||
if (this.highlightTimer) {
|
||||
this.highlightTimer.cancel();
|
||||
this.highlightTimer = null;
|
||||
}
|
||||
ZoteroPane_Local.collectionsView.setHighlightedRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Highlights collections containing selected items on Ctrl (Win) or
|
||||
* Option/Alt (Mac/Linux) press
|
||||
*/
|
||||
function setHighlightedRowsCallback() {
|
||||
var itemIDs = ZoteroPane_Local.getSelectedItems(true);
|
||||
if (itemIDs && itemIDs.length) {
|
||||
var collectionIDs = Zotero.Collections.getCollectionsContainingItems(itemIDs, true);
|
||||
if (collectionIDs) {
|
||||
ZoteroPane_Local.collectionsView.setHighlightedRows(collectionIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handleKeyPress(event) {
|
||||
var from = event.originalTarget.id;
|
||||
|
||||
// Ignore keystrokes if Zotero pane is closed
|
||||
var zoteroPane = document.getElementById('zotero-pane-stack');
|
||||
if (zoteroPane.getAttribute('hidden') == 'true' ||
|
||||
zoteroPane.getAttribute('collapsed') == 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Zotero.locked) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if (from == 'zotero-collections-tree') {
|
||||
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||
event.keyCode == event.DOM_VK_DELETE) {
|
||||
var deleteItems = event.metaKey || (!Zotero.isMac && event.shiftKey);
|
||||
ZoteroPane_Local.deleteSelectedCollection(deleteItems);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (from == 'zotero-items-tree') {
|
||||
// Focus TinyMCE explicitly on tab key, since the normal focusing
|
||||
// doesn't work right
|
||||
|
@ -524,15 +578,29 @@ var ZoteroPane = new function()
|
|||
}, 0);
|
||||
}
|
||||
}
|
||||
else if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||
event.keyCode == event.DOM_VK_DELETE) {
|
||||
// If Cmd/Ctrl delete, use forced mode, which does different
|
||||
// things depending on the context
|
||||
var force = event.metaKey || (!Zotero.isMac && event.shiftKey);
|
||||
ZoteroPane_Local.deleteSelectedItems(force);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore keystrokes if Zotero pane is closed
|
||||
var zoteroPane = document.getElementById('zotero-pane-stack');
|
||||
if (zoteroPane.getAttribute('hidden') == 'true' ||
|
||||
zoteroPane.getAttribute('collapsed') == 'true') {
|
||||
else if (event.keyCode == event.DOM_VK_RETURN) {
|
||||
var items = this.itemsView.getSelectedItems();
|
||||
// Don't do anything if more than 20 items selected
|
||||
if (!items.length || items.length > 20) {
|
||||
return;
|
||||
}
|
||||
ZoteroPane_Local.viewItems(items, event);
|
||||
// These don't seem to do anything. Instead we override
|
||||
// the tree binding's _handleEnter method in itemTreeView.js.
|
||||
//event.preventDefault();
|
||||
//event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var useShift = Zotero.isMac;
|
||||
|
||||
|
@ -557,7 +625,6 @@ var ZoteroPane = new function()
|
|||
|
||||
// Errors don't seem to make it out otherwise
|
||||
try {
|
||||
|
||||
switch (command) {
|
||||
case 'openZotero':
|
||||
try {
|
||||
|
@ -571,7 +638,7 @@ var ZoteroPane = new function()
|
|||
catch (e) {
|
||||
Zotero.debug(e);
|
||||
}
|
||||
if(window.ZoteroOverlay) window.ZoteroOverlay.toggleDisplay()
|
||||
if (window.ZoteroOverlay) window.ZoteroOverlay.toggleDisplay()
|
||||
break;
|
||||
case 'library':
|
||||
document.getElementById('zotero-collections-tree').focus();
|
||||
|
@ -622,7 +689,6 @@ var ZoteroPane = new function()
|
|||
default:
|
||||
throw ('Command "' + command + '" not found in ZoteroPane_Local.handleKeyDown()');
|
||||
}
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e, 1);
|
||||
|
@ -633,72 +699,6 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
|
||||
function handleKeyUp(event, from) {
|
||||
if (from == 'zotero-pane') {
|
||||
if ((Zotero.isWin && event.keyCode == 17) ||
|
||||
(!Zotero.isWin && event.keyCode == 18)) {
|
||||
if (this.highlightTimer) {
|
||||
this.highlightTimer.cancel();
|
||||
this.highlightTimer = null;
|
||||
}
|
||||
ZoteroPane_Local.collectionsView.setHighlightedRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Highlights collections containing selected items on Ctrl (Win) or
|
||||
* Option/Alt (Mac/Linux) press
|
||||
*/
|
||||
function setHighlightedRowsCallback() {
|
||||
var itemIDs = ZoteroPane_Local.getSelectedItems(true);
|
||||
if (itemIDs && itemIDs.length) {
|
||||
var collectionIDs = Zotero.Collections.getCollectionsContainingItems(itemIDs, true);
|
||||
if (collectionIDs) {
|
||||
ZoteroPane_Local.collectionsView.setHighlightedRows(collectionIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handleKeyPress(event, from) {
|
||||
if (from == 'zotero-collections-tree') {
|
||||
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||
event.keyCode == event.DOM_VK_DELETE) {
|
||||
var deleteItems = event.metaKey || (!Zotero.isMac && event.shiftKey);
|
||||
ZoteroPane_Local.deleteSelectedCollection(deleteItems);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (from == 'zotero-items-tree') {
|
||||
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||
event.keyCode == event.DOM_VK_DELETE) {
|
||||
// If Cmd/Ctrl delete, use forced mode, which does different
|
||||
// things depending on the context
|
||||
var force = event.metaKey || (!Zotero.isMac && event.shiftKey);
|
||||
ZoteroPane_Local.deleteSelectedItems(force);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
else if (event.keyCode == event.DOM_VK_RETURN) {
|
||||
var items = this.itemsView.getSelectedItems();
|
||||
// Don't do anything if more than 20 items selected
|
||||
if (!items.length || items.length > 20) {
|
||||
return;
|
||||
}
|
||||
ZoteroPane_Local.viewItems(items, event);
|
||||
// These don't seem to do anything. Instead we override
|
||||
// the tree binding's _handleEnter method in itemTreeView.js.
|
||||
//event.preventDefault();
|
||||
//event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a new item
|
||||
*
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
<vbox id="zotero-pane"
|
||||
onkeydown="ZoteroPane_Local.handleKeyDown(event, this.id)"
|
||||
onkeyup="ZoteroPane_Local.handleKeyUp(event, this.id)"
|
||||
onkeypress="ZoteroPane_Local.handleKeyPress(event)"
|
||||
chromedir="&locale.dir;">
|
||||
|
||||
<toolbar id="zotero-toolbar" class="toolbar toolbar-primary">
|
||||
|
@ -299,7 +300,6 @@
|
|||
the tag selector to max height -->
|
||||
<tree id="zotero-collections-tree" hidecolumnpicker="true" context="zotero-collectionmenu"
|
||||
onmouseover="ZoteroPane_Local.collectionsView.setHighlightedRows();"
|
||||
onkeypress="ZoteroPane_Local.handleKeyPress(event, this.id)"
|
||||
onselect="ZoteroPane_Local.onCollectionSelected();"
|
||||
ondragstart="if (event.target.localName == 'treechildren') { ZoteroPane_Local.collectionsView.onDragStart(event); }"
|
||||
ondragenter="return ZoteroPane_Local.collectionsView.onDragEnter(event)"
|
||||
|
@ -337,7 +337,6 @@
|
|||
disableKeyNavigation="true"
|
||||
onfocus="if (ZoteroPane_Local.itemsView.rowCount && !ZoteroPane_Local.itemsView.selection.count) { ZoteroPane_Local.itemsView.selection.select(0); }"
|
||||
onkeydown="ZoteroPane_Local.handleKeyDown(event, this.id)"
|
||||
onkeypress="ZoteroPane_Local.handleKeyPress(event, this.id)"
|
||||
onselect="ZoteroPane_Local.itemSelected(event)"
|
||||
ondragstart="if (event.target.localName == 'treechildren') { ZoteroPane_Local.itemsView.onDragStart(event); }"
|
||||
ondragenter="return ZoteroPane_Local.itemsView.onDragEnter(event)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue