mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	The Event.which and Event.keyCode are deprecated as pointed out by TypeScript intellisense based on the jQuery types. We use Event.key instead which behaves similarly to Event.which & Event.keyCode for our use case. The only difference in functionality by this change is that the vim keys won't work when Caps Lock is on. This is because, in this case, the key property will be "J" instead of 'j'. We can fix this by adding a mapping for this, however, I think we don't want to handle this case so I left this change out. Tested by trying out the everywhere keydown_util is used. Finally, we also turn off the new-cap rule for tests since I think it fine to only enforce it on real code and exempting test code is fine.
		
			
				
	
	
		
			44 lines
		
	
	
		
			865 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			865 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const {zrequire} = require("../zjsunit/namespace");
 | 
						|
const {run_test} = require("../zjsunit/test");
 | 
						|
const $ = require("../zjsunit/zjquery");
 | 
						|
 | 
						|
const keydown_util = zrequire("keydown_util");
 | 
						|
 | 
						|
run_test("test_early_returns", () => {
 | 
						|
    const stub = $.create("stub");
 | 
						|
    const opts = {
 | 
						|
        elem: stub,
 | 
						|
        handlers: {
 | 
						|
            ArrowLeft: () => {
 | 
						|
                throw new Error("do not dispatch this with alt key");
 | 
						|
            },
 | 
						|
        },
 | 
						|
    };
 | 
						|
 | 
						|
    keydown_util.handle(opts);
 | 
						|
 | 
						|
    const e1 = {
 | 
						|
        type: "keydown",
 | 
						|
        key: "a", // not in keys
 | 
						|
    };
 | 
						|
 | 
						|
    stub.trigger(e1);
 | 
						|
 | 
						|
    const e2 = {
 | 
						|
        type: "keydown",
 | 
						|
        key: "Enter", // no handler
 | 
						|
    };
 | 
						|
 | 
						|
    stub.trigger(e2);
 | 
						|
 | 
						|
    const e3 = {
 | 
						|
        type: "keydown",
 | 
						|
        key: "ArrowLeft",
 | 
						|
        altKey: true, // let browser handle
 | 
						|
    };
 | 
						|
 | 
						|
    stub.trigger(e3);
 | 
						|
});
 |