Skip to content

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

FIX: rich editor getSelected.value to return markdown (#36483)

Renato Atilio8d02c267cf14
diff --git a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js
index 63e43e3ae2a..22138119f4c 100644
--- a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js
+++ b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.js
@@ -71,7 +71,7 @@ export default class ProsemirrorTextManipulation {
getSelected() {
const start = this.view.state.selection.from;
const end = this.view.state.selection.to;
- const value = this.view.state.doc.textBetween(start, end, " ", " ");
+ const value = this.convertToMarkdown(this.view.state.selection.content());
return {
start,
end,
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
index f70c2498eb6..6e9401d97a4 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
@@ -200,6 +200,35 @@ RSpec.describe "AI Composer helper", type: :system do
expect(composer.composer_input.value).to eq(proofread_text)
end
end
+
+ it "replaces selected formatted content from rich editor as markdown" do
+ visit("/latest")
+ page.find("#create-topic").click
+
+ composer.toggle_rich_editor
+ expect(composer).to have_rich_editor_active
+
+ composer.focus
+ composer.type_content("This is **bld text** and *itlic text* with `cde`.")
+
+ composer.select_all
+
+ composer.click_toolbar_button("ai-helper-trigger")
+ expect(ai_helper_menu).to have_context_menu
+
+ proofread_text = "This is **bold text** and *italic text* with `code`."
+
+ DiscourseAi::Completions::Llm.with_prepared_responses([proofread_text]) do
+ ai_helper_menu.select_helper_model(mode)
+ diff_modal.confirm_changes
+
+ composer.toggle_rich_editor
+ expect(composer).to have_no_rich_editor_active
+
+ wait_for { composer.composer_input.value == proofread_text }
+ expect(composer.composer_input.value).to eq(proofread_text)
+ end
+ end
end
end