mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(extension): restore global save shortcut
This commit is contained in:
parent
e651045ac5
commit
85531aa9fc
3 changed files with 65 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { MESSAGE_TYPES } from "../../utils/constants"
|
||||
import { isSaveMemoryShortcut } from "../../utils/keyboard-shortcut"
|
||||
import { bearerToken, userData } from "../../utils/storage"
|
||||
import type { APIResponse } from "../../utils/types"
|
||||
import { DOMUtils } from "../../utils/ui-components"
|
||||
|
|
@ -94,11 +95,7 @@ export async function saveMemory(
|
|||
|
||||
export function setupGlobalKeyboardShortcut() {
|
||||
document.addEventListener("keydown", async (event) => {
|
||||
if (
|
||||
(event.ctrlKey || event.metaKey) &&
|
||||
event.shiftKey &&
|
||||
event.key === "m"
|
||||
) {
|
||||
if (isSaveMemoryShortcut(event)) {
|
||||
event.preventDefault()
|
||||
await saveMemory("keyboard_shortcut")
|
||||
}
|
||||
|
|
|
|||
50
apps/browser-extension/utils/keyboard-shortcut.test.ts
Normal file
50
apps/browser-extension/utils/keyboard-shortcut.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { describe, expect, it } from "bun:test"
|
||||
import {
|
||||
isSaveMemoryShortcut,
|
||||
type SaveMemoryShortcutEvent,
|
||||
} from "./keyboard-shortcut"
|
||||
|
||||
function shortcutEvent(
|
||||
overrides: Partial<SaveMemoryShortcutEvent> = {},
|
||||
): SaveMemoryShortcutEvent {
|
||||
return {
|
||||
ctrlKey: false,
|
||||
key: "M",
|
||||
metaKey: false,
|
||||
repeat: false,
|
||||
shiftKey: true,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe("isSaveMemoryShortcut", () => {
|
||||
it("accepts uppercase M from Ctrl+Shift+M", () => {
|
||||
expect(isSaveMemoryShortcut(shortcutEvent({ ctrlKey: true }))).toBeTrue()
|
||||
})
|
||||
|
||||
it("accepts uppercase M from Command+Shift+M", () => {
|
||||
expect(isSaveMemoryShortcut(shortcutEvent({ metaKey: true }))).toBeTrue()
|
||||
})
|
||||
|
||||
it("accepts lowercase key representations", () => {
|
||||
expect(
|
||||
isSaveMemoryShortcut(shortcutEvent({ ctrlKey: true, key: "m" })),
|
||||
).toBeTrue()
|
||||
})
|
||||
|
||||
it("rejects missing modifiers and other keys", () => {
|
||||
expect(isSaveMemoryShortcut(shortcutEvent())).toBeFalse()
|
||||
expect(
|
||||
isSaveMemoryShortcut(shortcutEvent({ ctrlKey: true, shiftKey: false })),
|
||||
).toBeFalse()
|
||||
expect(
|
||||
isSaveMemoryShortcut(shortcutEvent({ ctrlKey: true, key: "N" })),
|
||||
).toBeFalse()
|
||||
})
|
||||
|
||||
it("rejects repeated keydown events", () => {
|
||||
expect(
|
||||
isSaveMemoryShortcut(shortcutEvent({ ctrlKey: true, repeat: true })),
|
||||
).toBeFalse()
|
||||
})
|
||||
})
|
||||
13
apps/browser-extension/utils/keyboard-shortcut.ts
Normal file
13
apps/browser-extension/utils/keyboard-shortcut.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export type SaveMemoryShortcutEvent = Pick<
|
||||
KeyboardEvent,
|
||||
"ctrlKey" | "key" | "metaKey" | "repeat" | "shiftKey"
|
||||
>
|
||||
|
||||
export function isSaveMemoryShortcut(event: SaveMemoryShortcutEvent): boolean {
|
||||
return (
|
||||
!event.repeat &&
|
||||
(event.ctrlKey || event.metaKey) &&
|
||||
event.shiftKey &&
|
||||
event.key.toLowerCase() === "m"
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue