From 3de556f3eaaae7c59f1d3b85278f3ade2fc19f41 Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Fri, 8 Nov 2024 16:40:50 +0800 Subject: [PATCH 1/3] Adding Shortcuts (enter,ctrl + enter) --- src/home/room_screen.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 959a701..f8b5081 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1254,9 +1254,27 @@ impl Widget for RoomScreen { } } - // Handle the send message button being clicked. - if self.button(id!(send_message_button)).clicked(&actions) { - let msg_input_widget = self.text_input(id!(message_input)); + let msg_input_widget = self.text_input(id!(message_input)); + // Handle the Ctrl+Enter key combination to add a new line in the message input box. + if let Some( + KeyEvent{ + key_code: KeyCode::ReturnKey, + modifiers: KeyModifiers{ + control: true, + .. + }, + .. + }) = msg_input_widget.key_down_unhandled(&actions) { + + let msg_len = msg_input_widget.text().len(); + + msg_input_widget.set_text(&(msg_input_widget.text() + "\n")); + msg_input_widget.set_cursor(msg_len, msg_len); + msg_input_widget.redraw(cx); + } + + // Handle the send message button being clicked and enter key being pressed. + if self.button(id!(send_message_button)).clicked(&actions) || msg_input_widget.returned(&actions).is_some() { let entered_text = msg_input_widget.text(); if !entered_text.is_empty() { let room_id = self.room_id.clone().unwrap(); From 882e350d1fc04f16c4512c146060748a76120edb Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Mon, 11 Nov 2024 16:38:18 +0800 Subject: [PATCH 2/3] Finish add enter and ctrl + enter shortcut to send message --- src/home/room_screen.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 0c6f5c1..9f08f73 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1274,27 +1274,19 @@ impl Widget for RoomScreen { } let msg_input_widget = self.text_input(id!(message_input)); - // Handle the Ctrl+Enter key combination to add a new line in the message input box. - if let Some( - KeyEvent{ - key_code: KeyCode::ReturnKey, - modifiers: KeyModifiers{ - control: true, - .. - }, - .. - }) = msg_input_widget.key_down_unhandled(&actions) { - - let msg_len = msg_input_widget.text().len(); - - msg_input_widget.set_text(&(msg_input_widget.text() + "\n")); - msg_input_widget.set_cursor(msg_len, msg_len); - msg_input_widget.redraw(cx); + if let Some(key_event) = msg_input_widget.key_down_unhandled(&actions) { + // Handle the Ctrl+Enter key combination to add a new line in the message input box. + if key_event.key_code == KeyCode::ReturnKey && key_event.modifiers.control { + let msg_len = msg_input_widget.text().len(); + msg_input_widget.set_text(&(msg_input_widget.text() + "\n")); + msg_input_widget.set_cursor(msg_len, msg_len); + msg_input_widget.redraw(cx); + } } // Handle the send message button being clicked and enter key being pressed. if self.button(id!(send_message_button)).clicked(&actions) || msg_input_widget.returned(&actions).is_some() { - let entered_text = msg_input_widget.text(); + let entered_text = msg_input_widget.text().trim().to_string(); if !entered_text.is_empty() { let room_id = self.room_id.clone().unwrap(); log!("Sending message to room {}: {:?}", room_id, entered_text); From e93fd271a73c670e31bcf3a71231b27404859532 Mon Sep 17 00:00:00 2001 From: Tyrese Luo Date: Tue, 12 Nov 2024 11:29:43 +0800 Subject: [PATCH 3/3] Only add window and mac shortcuts for send messages --- src/home/room_screen.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 3e7d4d9..0ca9b8e 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1304,18 +1304,20 @@ impl Widget for RoomScreen { } let msg_input_widget = self.text_input(id!(message_input)); + + let mut send_message_with_shortcut_key = false; if let Some(key_event) = msg_input_widget.key_down_unhandled(&actions) { - // Handle the Ctrl+Enter key combination to add a new line in the message input box. - if key_event.key_code == KeyCode::ReturnKey && key_event.modifiers.control { - let msg_len = msg_input_widget.text().len(); - msg_input_widget.set_text(&(msg_input_widget.text() + "\n")); - msg_input_widget.set_cursor(msg_len, msg_len); - msg_input_widget.redraw(cx); + + // Windows and linux use control key, mac uses logo key + if key_event.key_code == KeyCode::ReturnKey + && (key_event.modifiers.control || key_event.modifiers.logo) + { + send_message_with_shortcut_key = true; } } // Handle the send message button being clicked and enter key being pressed. - if self.button(id!(send_message_button)).clicked(&actions) || msg_input_widget.returned(&actions).is_some() { + if self.button(id!(send_message_button)).clicked(&actions) || send_message_with_shortcut_key { let entered_text = msg_input_widget.text().trim().to_string(); if !entered_text.is_empty() { let room_id = self.room_id.clone().unwrap();