mirror of https://github.com/zulip/zulip.git
hotkey: Make 'Ctrl' hotkeys work with 'CMD' on MacOS.
We only have a couple hotkeys with this model, but they should both do the correct corresponding thing on MacOS.
This commit is contained in:
parent
19806a0283
commit
66edc003ca
|
@ -14,6 +14,10 @@
|
|||
set_global('activity', {
|
||||
});
|
||||
|
||||
set_global('navigator', {
|
||||
userAgent: '',
|
||||
});
|
||||
|
||||
set_global('page_params', {
|
||||
});
|
||||
|
||||
|
@ -66,11 +70,12 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
});
|
||||
}
|
||||
|
||||
function map_down(which, shiftKey, ctrlKey) {
|
||||
function map_down(which, shiftKey, ctrlKey, metaKey) {
|
||||
return hotkey.get_keydown_hotkey({
|
||||
which: which,
|
||||
shiftKey: shiftKey,
|
||||
ctrlKey: ctrlKey,
|
||||
metaKey: metaKey,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -93,8 +98,8 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
assert.equal(map_press(47).name, 'search'); // slash
|
||||
assert.equal(map_press(106).name, 'vim_down'); // j
|
||||
|
||||
assert.equal(map_down(219, false, true).name, 'escape');
|
||||
assert.equal(map_down(75, false, true).name, 'search');
|
||||
assert.equal(map_down(219, false, true).name, 'escape'); // ctrl + [
|
||||
assert.equal(map_down(75, false, true).name, 'search'); // ctrl + k
|
||||
|
||||
// More negative tests.
|
||||
assert.equal(map_down(47), undefined);
|
||||
|
@ -114,6 +119,17 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
assert.equal(map_down(88, false, true), undefined); // ctrl + x
|
||||
assert.equal(map_down(78, false, true), undefined); // ctrl + n
|
||||
assert.equal(map_down(77, false, true), undefined); // ctrl + m
|
||||
assert.equal(map_down(75, false, false, true), undefined); // cmd + k
|
||||
|
||||
// CMD tests for MacOS
|
||||
global.navigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36";
|
||||
assert.equal(map_down(219, false, false, true).name, 'escape'); // cmd + [
|
||||
assert.equal(map_down(75, false, false, true).name, 'search'); // cmd + k
|
||||
|
||||
assert.equal(map_down(75, false, true, false), undefined); // ctrl + k
|
||||
|
||||
// Reset userAgent
|
||||
global.navigator.userAgent = '';
|
||||
}());
|
||||
|
||||
(function test_basic_chars() {
|
||||
|
|
|
@ -47,7 +47,7 @@ var keydown_unshift_mappings = {
|
|||
40: {name: 'down_arrow', message_view_only: false}, // down arrow
|
||||
};
|
||||
|
||||
var keydown_ctrl_mappings = {
|
||||
var keydown_cmd_or_ctrl_mappings = {
|
||||
75: {name: 'search', message_view_only: false}, // 'K'
|
||||
219: {name: 'escape', message_view_only: false}, // '['
|
||||
};
|
||||
|
@ -107,17 +107,21 @@ var keypress_mappings = {
|
|||
};
|
||||
|
||||
exports.get_keydown_hotkey = function (e) {
|
||||
if (e.metaKey || e.altKey) {
|
||||
if (e.altKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
var hotkey;
|
||||
if (e.ctrlKey) {
|
||||
hotkey = keydown_ctrl_mappings[e.which];
|
||||
|
||||
var isCmdOrCtrl = /Mac/i.test(navigator.userAgent) ? e.metaKey : e.ctrlKey;
|
||||
if (isCmdOrCtrl) {
|
||||
hotkey = keydown_cmd_or_ctrl_mappings[e.which];
|
||||
if (hotkey) {
|
||||
return hotkey;
|
||||
}
|
||||
return;
|
||||
} else if (e.metaKey || e.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.shiftKey) {
|
||||
|
|
Loading…
Reference in New Issue