mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
UX: adds chat send shortcut user preference (#30473)
Users can now decide if they want to send a message on: - <kbd>enter</kbd> - <kbd>meta + enter</kbd> If you choose <kbd>meta + enter</kbd>, <kbd>enter</kbd> will add a linebreak. <img width="192" alt="Screenshot 2025-01-21 at 12 57 48" src="https://github.com/user-attachments/assets/abfd6f8b-83b3-4e6f-be67-8f63d536ca8a" />
This commit is contained in:
@ -104,6 +104,74 @@ RSpec.describe "Chat composer", type: :system do
|
||||
|
||||
expect(channel_page.composer.value).to eq("bb")
|
||||
end
|
||||
|
||||
context "when user preference is set to send on enter" do
|
||||
before { current_user.user_option.update!(chat_send_shortcut: 0) }
|
||||
|
||||
context "when pressing enter" do
|
||||
it "sends the message" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").enter_shortcut
|
||||
|
||||
expect(channel_page.messages).to have_message(text: "testenter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when pressing shift + enter" do
|
||||
it "adds a linebreak" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").shift_enter_shortcut
|
||||
|
||||
expect(channel_page.composer.value).to eq("testenter\n")
|
||||
end
|
||||
end
|
||||
|
||||
context "when pressing meta + enter" do
|
||||
it "sends the message" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").meta_enter_shortcut
|
||||
|
||||
expect(channel_page.messages).to have_message(text: "testenter")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when user preference is set to send on meta + enter" do
|
||||
before { current_user.user_option.update!(chat_send_shortcut: 1) }
|
||||
|
||||
context "when pressing enter" do
|
||||
it "adds a linebreak" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").enter_shortcut
|
||||
|
||||
expect(channel_page.composer.value).to eq("testenter\n")
|
||||
end
|
||||
end
|
||||
|
||||
context "when pressing shift + enter" do
|
||||
it "adds a linebreak" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").shift_enter_shortcut
|
||||
|
||||
expect(channel_page.composer.value).to eq("testenter\n")
|
||||
end
|
||||
end
|
||||
|
||||
context "when pressing meta + enter" do
|
||||
it "sends the message" do
|
||||
chat_page.visit_channel(channel_1)
|
||||
|
||||
channel_page.composer.fill_in(with: "testenter").meta_enter_shortcut
|
||||
|
||||
expect(channel_page.messages).to have_message(text: "testenter")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when editing a message with no length" do
|
||||
|
@ -42,6 +42,7 @@ module PageObjects
|
||||
|
||||
def fill_in(**args)
|
||||
input.fill_in(**args)
|
||||
self
|
||||
end
|
||||
|
||||
def value
|
||||
@ -105,6 +106,18 @@ module PageObjects
|
||||
def focused?
|
||||
component.has_css?(".chat-composer.is-focused")
|
||||
end
|
||||
|
||||
def enter_shortcut
|
||||
input.send_keys(:enter)
|
||||
end
|
||||
|
||||
def shift_enter_shortcut
|
||||
input.send_keys(%i[shift enter])
|
||||
end
|
||||
|
||||
def meta_enter_shortcut
|
||||
input.send_keys([PLATFORM_KEY_MODIFIER, :enter])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,6 +62,15 @@ RSpec.describe "User chat preferences", type: :system do
|
||||
expect(select_kit).to have_selected_value("fullscreen")
|
||||
end
|
||||
|
||||
it "can select send shorcut sidebar mode" do
|
||||
visit("/my/preferences")
|
||||
find(".user-nav__preferences-chat", visible: :all).click
|
||||
find("#chat_send_shortcut_meta_enter").click
|
||||
find(".save-changes").click
|
||||
|
||||
expect(page).to have_checked_field("chat_send_shortcut_meta_enter")
|
||||
end
|
||||
|
||||
context "as an admin on another user's preferences" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
|
Reference in New Issue
Block a user