Skip to content

A platform for community discussion. Free, open, simple.

FIX: Composer mode was not being remembered on new PM (#33962)

Martin Brennan8763cdb477f7
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.gjs b/app/assets/javascripts/discourse/app/components/d-editor.gjs
index 9fd2603019a..1012a034abe 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.gjs
+++ b/app/assets/javascripts/discourse/app/components/d-editor.gjs
@@ -94,9 +94,9 @@ export default class DEditor extends Component {
this.setupToolbar();
- // TODO (martin) Remove this once we are sure all users have migrated
- // to the new rich editor preference, or a few months after the 3.5 release.
if (this.siteSettings.rich_editor) {
+ // TODO (martin) Remove this once we are sure all users have migrated
+ // to the new rich editor preference, or a few months after the 3.5 release.
await this.handleOldRichEditorPreference();
if (this.currentUser.useRichEditor) {
diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rb
index 4bdefe81e1c..7e2253e27f5 100644
--- a/app/serializers/user_option_serializer.rb
+++ b/app/serializers/user_option_serializer.rb
@@ -43,7 +43,8 @@ class UserOptionSerializer < ApplicationSerializer
:sidebar_link_to_filtered_list,
:sidebar_show_count_of_new_items,
:watched_precedence_over_muted,
- :topics_unread_when_closed
+ :topics_unread_when_closed,
+ :composition_mode
def auto_track_topics_after_msecs
object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs
diff --git a/spec/requests/api/schemas/json/user_get_response.json b/spec/requests/api/schemas/json/user_get_response.json
index 6e2854d2cc4..c2c94d65fe9 100644
--- a/spec/requests/api/schemas/json/user_get_response.json
+++ b/spec/requests/api/schemas/json/user_get_response.json
@@ -815,6 +815,9 @@
},
"topics_unread_when_closed": {
"type": "boolean"
+ },
+ "composition_mode": {
+ "type": "integer"
}
},
"required": [
diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rb
index b1f8ecc9603..8caa50bd65f 100644
--- a/spec/system/composer/prosemirror_editor_spec.rb
+++ b/spec/system/composer/prosemirror_editor_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Composer - ProseMirror editor", type: :system do
- fab!(:user) do
+ fab!(:current_user) do
Fabricate(
:user,
refresh_auto_groups: true,
@@ -14,7 +14,7 @@ describe "Composer - ProseMirror editor", type: :system do
let(:composer) { PageObjects::Components::Composer.new }
let(:rich) { composer.rich_editor }
- before { sign_in(user) }
+ before { sign_in(current_user) }
def open_composer
page.visit "/new-topic"
@@ -40,16 +40,29 @@ describe "Composer - ProseMirror editor", type: :system do
expect(composer).to have_composer_preview_toggle
end
- it "saves the user's rich editor preference to the database" do
+ it "saves the user's rich editor preference and remembers it when reopening the composer" do
open_composer
+ expect(composer).to have_rich_editor_active
composer.toggle_rich_editor
- expect(page).to have_css(".composer-toggle-switch.--markdown")
+ expect(composer).to have_markdown_editor_active
try_until_success(frequency: 0.5) do
- expect(user.user_option.reload.composition_mode).to eq(
+ expect(current_user.user_option.reload.composition_mode).to eq(
UserOption.composition_mode_types[:markdown],
)
end
+
+ visit("/")
+ open_composer
+ expect(composer).to have_markdown_editor_active
+ end
+
+ it "remembers the user's rich editor preference when starting a new PM" do
+ current_user.user_option.update!(composition_mode: UserOption.composition_mode_types[:rich])
+ page.visit("/u/#{current_user.username}/messages")
+ find(".new-private-message").click
+ expect(composer).to be_opened
+ expect(composer).to have_rich_editor_active
end
# TODO (martin) Remove this once we are sure all users have migrated
@@ -68,7 +81,7 @@ describe "Composer - ProseMirror editor", type: :system do
expect(composer).to have_rich_editor
try_until_success(frequency: 0.5) do
- expect(user.user_option.reload.composition_mode).to eq(
+ expect(current_user.user_option.reload.composition_mode).to eq(
UserOption.composition_mode_types[:rich],
)
end
@@ -83,7 +96,7 @@ describe "Composer - ProseMirror editor", type: :system do
context "with autocomplete" do
it "triggers an autocomplete on mention" do
open_composer
- composer.type_content("@#{user.username}")
+ composer.type_content("@#{current_user.username}")
expect(composer).to have_mention_autocomplete
end
@@ -939,19 +952,19 @@ describe "Composer - ProseMirror editor", type: :system do
before do
Draft.set(
- user,
+ current_user,
topic.draft_key,
0,
- { reply: "hey @#{user.username} and @unknown - how are you?" }.to_json,
+ { reply: "hey @#{current_user.username} and @unknown - how are you?" }.to_json,
)
end
it "validates manually typed mentions" do
open_composer
- composer.type_content("Hey @#{user.username} ")
+ composer.type_content("Hey @#{current_user.username} ")
- expect(rich).to have_css("a.mention", text: user.username)
+ expect(rich).to have_css("a.mention", text: current_user.username)
composer.type_content("and @invalid_user - how are you?")
@@ -959,7 +972,9 @@ describe "Composer - ProseMirror editor", type: :system do
composer.toggle_rich_editor
- expect(composer).to have_value("Hey @#{user.username} and @invalid_user - how are you?")
+ expect(composer).to have_value(
+ "Hey @#{current_user.username} and @invalid_user - how are you?",
+ )
end
it "validates mentions in drafts" do
@@ -967,7 +982,7 @@ describe "Composer - ProseMirror editor", type: :system do
expect(composer).to be_opened
- expect(rich).to have_css("a.mention", text: user.username)
+ expect(rich).to have_css("a.mention", text: current_user.username)
expect(rich).to have_no_css("a.mention", text: "@unknown")
end
diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rb
index bad738a68d4..5018e8eb712 100644
--- a/spec/system/page_objects/components/composer.rb
+++ b/spec/system/page_objects/components/composer.rb
@@ -329,11 +329,15 @@ module PageObjects
end
def has_rich_editor_active?
- find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch__right-icon.--active")
+ find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch.--rte")
end
def has_no_rich_editor_active?
- find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch__left-icon.--active")
+ find("#{COMPOSER_ID}").has_css?(".composer-toggle-switch.--markdown")
+ end
+
+ def has_markdown_editor_active?
+ has_no_rich_editor_active?
end
def toggle_rich_editor