mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 00:43:40 +08:00
51016e56dd
Merges the design experiment at https://meta.discourse.org/t/post-quote-copy-to-clipboard-button-feedback/285376 into core. This adds a new button by default to the menu that pops up when text is selected in a post. The normal Quote button that is shown when selecting text within a post will open the composer with the quote markdown prefilled. This new "Copy Quote" button copies the quote markdown directly to the user’s clipboard. This is useful for when you want to copy the quote elsewhere – to another topic or a chat message for instance – without having to manually copy from the opened composer, which then has to be dismissed afterwards. An example of quote markdown: ``` [quote="someuser, post:7, topic:285376"] In this moment, I am euphoric. [/quote] ```
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Post selection | Copy quote", type: :system do
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
let(:cdp) { PageObjects::CDP.new }
|
|
|
|
fab!(:topic)
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "Hello world it's time for quoting!") }
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
before do
|
|
sign_in(current_user)
|
|
cdp.allow_clipboard
|
|
end
|
|
|
|
it "copies the selection from the post the clipboard" do
|
|
topic_page.visit_topic(topic)
|
|
|
|
select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
|
|
topic_page.copy_quote_button.click
|
|
|
|
expect(cdp.read_clipboard.chomp).to eq(<<~QUOTE.chomp)
|
|
[quote=\"#{post.user.username}, post:1, topic:#{topic.id}\"]\nHello worl\n[/quote]\n
|
|
QUOTE
|
|
end
|
|
|
|
it "does not show the copy quote button if it has been disabled" do
|
|
SiteSetting.enable_quote_copy = false
|
|
topic_page.visit_topic(topic)
|
|
|
|
select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
|
|
expect(page).not_to have_css(topic_page.copy_quote_button_selector)
|
|
end
|
|
end
|