From 51016e56dd99a9ad4bd82cdc6c0cf968754c70ed Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 8 Jan 2024 10:38:14 +1000 Subject: [PATCH] FEATURE: Add copy quote button to post selection menu (#25139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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] ``` --- .../post-text-selection-toolbar.gjs | 29 +++++++++++++++- .../app/components/post-text-selection.gjs | 5 +++ config/locales/client.en.yml | 2 ++ config/locales/server.en.yml | 3 +- config/site_settings.yml | 3 ++ spec/system/page_objects/pages/topic.rb | 8 +++++ spec/system/post_selection_copy_quote_spec.rb | 34 +++++++++++++++++++ ...ec.rb => post_selection_fast_edit_spec.rb} | 2 +- 8 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 spec/system/post_selection_copy_quote_spec.rb rename spec/system/{fast_edit_spec.rb => post_selection_fast_edit_spec.rb} (96%) diff --git a/app/assets/javascripts/discourse/app/components/post-text-selection-toolbar.gjs b/app/assets/javascripts/discourse/app/components/post-text-selection-toolbar.gjs index 4fdc6853c15..8b3e95b9402 100644 --- a/app/assets/javascripts/discourse/app/components/post-text-selection-toolbar.gjs +++ b/app/assets/javascripts/discourse/app/components/post-text-selection-toolbar.gjs @@ -12,8 +12,13 @@ import PluginOutlet from "discourse/components/plugin-outlet"; import concatClass from "discourse/helpers/concat-class"; import { ajax } from "discourse/lib/ajax"; import Sharing from "discourse/lib/sharing"; -import { postUrl, setCaretPosition } from "discourse/lib/utilities"; +import { + clipboardCopy, + postUrl, + setCaretPosition, +} from "discourse/lib/utilities"; import { getAbsoluteURL } from "discourse-common/lib/get-url"; +import I18n from "discourse-i18n"; export function fixQuotes(str) { // u+201c, u+201d = “ ” @@ -27,6 +32,7 @@ export default class PostTextSelectionToolbar extends Component { @service site; @service siteSettings; @service appEvents; + @service toasts; @tracked isFastEditing = false; @@ -96,6 +102,17 @@ export default class PostTextSelectionToolbar extends Component { event.stopPropagation(); } + @action + async copyQuoteToClipboard() { + const text = await this.args.data.buildQuote(); + clipboardCopy(text); + this.toasts.success({ + duration: 3000, + data: { message: I18n.t("post.quote_copied_to_clibboard") }, + }); + await this.args.data.hideToolbar(); + } + @action async closeFastEdit() { this.isFastEditing = false; @@ -216,6 +233,16 @@ export default class PostTextSelectionToolbar extends Component { /> {{/if}} + {{#if @data.canCopyQuote}} + + {{/if}} +