hotkey: Change the keyboard mapping of ctrl_enter.

This commit changes the keyboard mapping of Ctrl+Enter from
keydown_ctrl_mappings to keydown_cmd_or_ctrl_mappings. This
fix addresses the problem where Cmd+Enter was not sending the
message in preview mode. Additionally, to ensure that Ctrl+Enter
also works, we had to modify the if block to not only check
isCmdOrCtrl but also Ctrl+Enter key combination with ASCII value of
13. This is because on Mac, the isCmdOrCtrl variable is true for
Cmd but false for Ctrl, which led to skipping the if block check
for Ctrl+Enter.
This commit is contained in:
Palash Baderia 2022-10-11 17:50:27 +05:30 committed by palashb01
parent ca40e60469
commit c66f640ef5
1 changed files with 10 additions and 2 deletions

View File

@ -95,10 +95,10 @@ const keydown_unshift_mappings = {
const keydown_ctrl_mappings = {
219: {name: "escape", message_view_only: false}, // '['
13: {name: "ctrl_enter", message_view_only: true}, // enter
};
const keydown_cmd_or_ctrl_mappings = {
13: {name: "ctrl_enter", message_view_only: true}, // enter
67: {name: "copy_with_c", message_view_only: false}, // 'C'
75: {name: "search_with_k", message_view_only: false}, // 'K'
83: {name: "star_message", message_view_only: true}, // 'S'
@ -183,7 +183,15 @@ export function get_keydown_hotkey(e) {
}
const isCmdOrCtrl = common.has_mac_keyboard() ? e.metaKey : e.ctrlKey;
if (isCmdOrCtrl && !e.shiftKey) {
// On Mac, isCmdOrCtrl is true for Cmd and false for Ctrl. However, the behavior
// of Cmd+Enter and Ctrl+Enter is the same on Mac, which is to send the message.
// Therefore, if the pressed key is Ctrl+Enter, checking isCmdOrCtrl alone would
// have skipped the below if condition for the Ctrl+Enter case. Thus, we should
// check for the Ctrl+Enter combination separately, as the ASCII value of Ctrl+Enter
// is 13, and we don't want the if block to run for all Ctrl hotkeys. So, we check
// for the ASCII 13 key combination only.
if ((isCmdOrCtrl && !e.shiftKey) || (e.ctrlKey && e.which === 13)) {
hotkey = keydown_cmd_or_ctrl_mappings[e.which];
if (hotkey) {
return hotkey;