-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
737e926
commit 452f6f0
Showing
8 changed files
with
26 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,21 @@ | ||
import { getCurrentItems } from "../utils/items"; | ||
import { KeyModifier } from "../utils/shorcut"; | ||
import { waitUntil } from "../utils/wait"; | ||
|
||
export { initWindowShortcuts, unInitWindowShortcuts, initReaderShortcuts }; | ||
export { initShortcuts }; | ||
|
||
function initWindowShortcuts(win: Window) { | ||
_initShortcuts(win); | ||
} | ||
|
||
function unInitWindowShortcuts(win: Window) { | ||
_unInitShortcuts(win); | ||
} | ||
|
||
function initReaderShortcuts() { | ||
Zotero.Reader.registerEventListener("renderToolbar", (event) => { | ||
const reader = event.reader; | ||
_initShortcuts(reader._iframeWindow); | ||
waitUntil( | ||
() => (reader._internalReader?._primaryView as any)?._iframeWindow, | ||
() => | ||
_initShortcuts( | ||
(reader._internalReader._primaryView as any)?._iframeWindow, | ||
), | ||
); | ||
}); | ||
} | ||
|
||
function _initShortcuts(win?: Window) { | ||
if (!win) { | ||
return; | ||
} | ||
win.addEventListener("keydown", savePressedKeys); | ||
win.addEventListener("keyup", triggerShortcut); | ||
} | ||
function initShortcuts() { | ||
ztoolkit.Keyboard.register(async (ev, options) => { | ||
ztoolkit.log(options.keyboard.getLocalized()); | ||
|
||
function _unInitShortcuts(win?: Window) { | ||
if (!win) { | ||
return; | ||
} | ||
win.removeEventListener("keydown", savePressedKeys); | ||
win.removeEventListener("keyup", triggerShortcut); | ||
} | ||
|
||
function savePressedKeys(e: KeyboardEvent) { | ||
if (!addon.data.shortcut) { | ||
addon.data.shortcut = new KeyModifier(""); | ||
} | ||
const shortcut = addon.data.shortcut; | ||
shortcut.control = e.ctrlKey; | ||
shortcut.meta = e.metaKey; | ||
shortcut.shift = e.shiftKey; | ||
shortcut.alt = e.altKey; | ||
if (!["Shift", "Meta", "Ctrl", "Alt", "Control"].includes(e.key)) { | ||
shortcut.key = e.key; | ||
} | ||
} | ||
|
||
async function triggerShortcut(e: KeyboardEvent) { | ||
if (!addon.data.shortcut) { | ||
return; | ||
} | ||
const shortcut = new KeyModifier(addon.data.shortcut.getRaw()); | ||
addon.data.shortcut = undefined; | ||
|
||
const items = await getCurrentItems(); | ||
// Trigger action for multiple items | ||
await addon.api.actionManager.dispatchActionByShortcut(shortcut, { | ||
itemIDs: items.map((item) => item?.id), | ||
}); | ||
// Trigger action for each item | ||
for (const item of items) { | ||
await addon.api.actionManager.dispatchActionByShortcut(shortcut, { | ||
itemID: item.id, | ||
const items = await getCurrentItems(); | ||
// Trigger action for multiple items | ||
await addon.api.actionManager.dispatchActionByShortcut(options.keyboard, { | ||
itemIDs: items.map((item) => item?.id), | ||
}); | ||
} | ||
// Trigger action for each item | ||
for (const item of items) { | ||
await addon.api.actionManager.dispatchActionByShortcut(options.keyboard, { | ||
itemID: item.id, | ||
}); | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters