mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	fix(client): shortcut keys without modifiers affecting normal usage
This commit is contained in:
		@@ -119,11 +119,6 @@ describe("shortcuts", () => {
 | 
			
		||||
            metaKey: options.metaKey || false
 | 
			
		||||
        } 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", () => {
 | 
			
		||||
            const event = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: true });
 | 
			
		||||
            expect(matchesShortcut(event, "ctrl+a")).toBe(true);
 | 
			
		||||
@@ -148,6 +143,11 @@ describe("shortcuts", () => {
 | 
			
		||||
            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", () => {
 | 
			
		||||
            const ctrlEvent = createKeyboardEvent({ key: "a", code: "KeyA", ctrlKey: 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 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 &&
 | 
			
		||||
           e.altKey === expectedAlt &&
 | 
			
		||||
           e.shiftKey === expectedShift &&
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user