Skip to content

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

UX: add trailing paragraph when pasting a [quote] at the end of a text block (#34037)

Renato Atilio04dbc622ab1e
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/quote.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/quote.js
index 9d6b95173e1..75f61679b81 100644
--- a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/quote.js
+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/quote.js
@@ -102,9 +102,27 @@ const extension = {
state.write("[/quote]\n\n");
},
},
- plugins({ pmState: { Plugin, NodeSelection } }) {
+ plugins({
+ pmState: { Plugin, NodeSelection },
+ pmModel: { Slice, Fragment },
+ }) {
return new Plugin({
props: {
+ transformPasted(slice, view) {
+ if (
+ view.endOfTextblock("forward") &&
+ slice.content.childCount === 1 &&
+ slice.content.firstChild.type.name === "quote"
+ ) {
+ const quote = slice.content.firstChild;
+ const paragraph = view.state.schema.nodes.paragraph.create();
+
+ return Slice.maxOpen(Fragment.from([quote, paragraph]), false);
+ }
+
+ return slice;
+ },
+
handleClickOn(view, pos, node, nodePos, event) {
if (
node.type.name === "quote" &&
diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rb
index 8b5d985aefa..aa8b0be283c 100644
--- a/spec/system/composer/prosemirror_editor_spec.rb
+++ b/spec/system/composer/prosemirror_editor_spec.rb
@@ -1497,4 +1497,18 @@ describe "Composer - ProseMirror editor", type: :system do
expect(rich).to have_css("h2", text: "This is a test")
end
end
+
+ describe "quote node" do
+ it "keeps the cursor outside quote when pasted" do
+ open_composer
+
+ markdown = "[quote]\nThis is a quote\n\n[/quote]"
+ cdp.copy_paste(markdown)
+ composer.type_content("This is a test")
+
+ composer.toggle_rich_editor
+
+ expect(composer).to have_value(markdown + "\n\nThis is a test")
+ end
+ end
end