mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
fix(client): shortcut keys without modifiers affecting normal usage
This commit is contained in:
parent
95b1c82ccb
commit
b4c20d9683
@ -119,11 +119,6 @@ describe("shortcuts", () => {
|
|||||||
metaKey: options.metaKey || false
|
metaKey: options.metaKey || false
|
||||||
} as KeyboardEvent);
|
} as KeyboardEvent);
|
||||||
|
|
||||||
it("should match simple key shortcuts", () => {
|
|
||||||
const event = createKeyboardEvent({ key: "a", code: "KeyA" });
|
|
||||||
expect(matchesShortcut(event, "a")).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should match shortcuts with modifiers", () => {
|
it("should match shortcuts with modifiers", () => {
|
||||||
const event = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: true });
|
const event = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: true });
|
||||||
expect(matchesShortcut(event, "ctrl+a")).toBe(true);
|
expect(matchesShortcut(event, "ctrl+a")).toBe(true);
|
||||||
@ -148,6 +143,11 @@ describe("shortcuts", () => {
|
|||||||
expect(matchesShortcut(event, "a")).toBe(false);
|
expect(matchesShortcut(event, "a")).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not match when no modifiers are used", () => {
|
||||||
|
const event = createKeyboardEvent({ key: "a", code: "KeyA" });
|
||||||
|
expect(matchesShortcut(event, "a")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle alternative modifier names", () => {
|
it("should handle alternative modifier names", () => {
|
||||||
const ctrlEvent = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: true });
|
const ctrlEvent = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: true });
|
||||||
expect(matchesShortcut(ctrlEvent, "control+a")).toBe(true);
|
expect(matchesShortcut(ctrlEvent, "control+a")).toBe(true);
|
||||||
|
@ -162,6 +162,11 @@ export function matchesShortcut(e: KeyboardEvent, shortcut: string): boolean {
|
|||||||
const expectedShift = modifiers.includes('shift');
|
const expectedShift = modifiers.includes('shift');
|
||||||
const expectedMeta = modifiers.includes('meta') || modifiers.includes('cmd') || modifiers.includes('command');
|
const expectedMeta = modifiers.includes('meta') || modifiers.includes('cmd') || modifiers.includes('command');
|
||||||
|
|
||||||
|
// Refuse key combinations that don't include modifiers because they interfere with the normal usage of the application.
|
||||||
|
if (!(expectedCtrl || expectedAlt || expectedShift || expectedMeta)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return e.ctrlKey === expectedCtrl &&
|
return e.ctrlKey === expectedCtrl &&
|
||||||
e.altKey === expectedAlt &&
|
e.altKey === expectedAlt &&
|
||||||
e.shiftKey === expectedShift &&
|
e.shiftKey === expectedShift &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user