mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add copy quote button to post selection menu (#25139)
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] ```
This commit is contained in:
@@ -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}}
|
||||
<DButton
|
||||
@icon="copy"
|
||||
@label="post.quote_copy"
|
||||
@title="post.quote_copy"
|
||||
class="btn-flat copy-quote"
|
||||
{{on "click" this.copyQuoteToClipboard}}
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
<PluginOutlet
|
||||
@name="quote-share-buttons-before"
|
||||
@connectorTagName="span"
|
||||
|
||||
@@ -204,6 +204,7 @@ export default class PostTextSelection extends Component {
|
||||
trapTab: false,
|
||||
data: {
|
||||
canEditPost: this.canEditPost,
|
||||
canCopyQuote: this.canCopyQuote,
|
||||
editPost: this.args.editPost,
|
||||
supportsFastEdit,
|
||||
topic: this.args.topic,
|
||||
@@ -258,6 +259,10 @@ export default class PostTextSelection extends Component {
|
||||
return this.siteSettings.enable_fast_edit && this.post?.can_edit;
|
||||
}
|
||||
|
||||
get canCopyQuote() {
|
||||
return this.siteSettings.enable_quote_copy;
|
||||
}
|
||||
|
||||
// on Desktop, shows the bar at the beginning of the selection
|
||||
// on Mobile, shows the bar at the end of the selection
|
||||
@cached
|
||||
|
||||
Reference in New Issue
Block a user